//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

//---------------------------------------------------------------------------
#include "stdio.h"
#include "GrvPH1.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)

//---------------------------------------------------------------------------
__fastcall TGrvPH::TGrvPH(void)
{
  R_10 = new struct REGISTRO_10;
  R_20S = new struct REGISTRO_20S;
  R_20E = new struct REGISTRO_20E;
  R_21S = new struct REGISTRO_21S;
  R_21E = new struct REGISTRO_21E;
  R_22 = new struct REGISTRO_22;
  R_23S = new struct REGISTRO_23S;
  R_23E = new struct REGISTRO_23E;
  R_24 = new struct REGISTRO_24;
  R_25 = new struct REGISTRO_25;
  R_26 = new struct REGISTRO_26;
  R_27 = new struct REGISTRO_27;
  R_28 = new struct REGISTRO_28;
  R_29 = new struct REGISTRO_29;
  R_30 = new struct REGISTRO_30;
  R_31 = new struct REGISTRO_31;
  R_32 = new struct REGISTRO_32;
  R_33 = new struct REGISTRO_33;
  R_34 = new struct REGISTRO_34;
  R_35 = new struct REGISTRO_35;
  R_36S = new struct REGISTRO_36S;
  R_36E = new struct REGISTRO_36E;
  R_37 = new struct REGISTRO_37;
  R_38 = new struct REGISTRO_38;
  R_41 = new struct REGISTRO_41;
  R_42 = new struct REGISTRO_42;
  R_44 = new struct REGISTRO_44;
  R_45 = new struct REGISTRO_45;
  R_46 = new struct REGISTRO_46;
  R_47 = new struct REGISTRO_47;
  R_47R = new struct REGISTRO_47R;
  R_47AQ = new struct REGISTRO_47AQ;
  R_47AE = new struct REGISTRO_47AE;
  R_47M = new struct REGISTRO_47M;
  R_48 = new struct REGISTRO_48;
  R_49 = new struct REGISTRO_49;
  R_50 = new struct REGISTRO_50;
  R_51 = new struct REGISTRO_51;
  R_52 = new struct REGISTRO_52;
  R_53 = new struct REGISTRO_53;
  R_54 = new struct REGISTRO_54;
  R_55 = new struct REGISTRO_55;
  R_58 = new struct REGISTRO_58;
  R_59 = new struct REGISTRO_59;
  R_60 = new struct REGISTRO_60;
  R_61 = new struct REGISTRO_61;
  R_62 = new struct REGISTRO_62;
  R_63 = new struct REGISTRO_63;
  R_65 = new struct REGISTRO_65;
  R_66 = new struct REGISTRO_66;
  R_67 = new struct REGISTRO_67;
  R_68 = new struct REGISTRO_68;
  R_75 = new struct REGISTRO_75;
  R_75->R_76 = new struct REGISTRO_76;
  R_75->R_76->R_77 = new struct REGISTRO_77;
  R_80 = new struct REGISTRO_80;
  R_81 = new struct REGISTRO_81;
  R_82 = new struct REGISTRO_82;
  R_83 = new struct REGISTRO_83;
  R_84 = new struct REGISTRO_84;
  R_85 = new struct REGISTRO_85;
  L_28 = new TList;
  L_29 = new TList;
  L_32 = new TList;
  L_33 = new TList;
  L_38 = new TList;
  L_41 = new TList;
  L_42 = new TList;
  L_44 = new TList;
  L_46 = new TList;
  L_48 = new TList;
  L_49 = new TList;
  L_50 = new TList;
  L_51 = new TList;
  L_52 = new TList;
  L_53 = new TList;
  L_54 = new TList;
  L_55 = new TList;
  L_58 = new TList;
  L_59 = new TList;
  L_60 = new TList;
  L_65 = new TList;
  L_75 = new TList;
  L_80 = new TList;
  L_83 = new TList;
  LimpaTodas();
  Contador = 0;
}

//---------------------------------------------------------------------------
__fastcall TGrvPH::~TGrvPH(void)
{
  LimpaTodas();
  delete R_10;
  delete R_20S;
  delete R_20E;
  delete R_21S;
  delete R_21E;
  delete R_22;
  delete R_23S;
  delete R_23E;
  delete R_24;
  delete R_25;
  delete R_26;
  delete R_27;
  delete R_28;
  delete R_29;
  delete R_30;
  delete R_31;
  delete R_32;
  delete R_33;
  delete R_34;
  delete R_35;
  delete R_36S;
  delete R_36E;
  delete R_37;
  delete R_38;
  delete R_41;
  delete R_42;
  delete R_44;
  delete R_45;
  delete R_46;
  delete R_47;
  delete R_47R;
  delete R_47AQ;
  delete R_47AE;
  delete R_47M;
  delete R_48;
  delete R_49;
  delete R_50;
  delete R_51;
  delete R_52;
  delete R_53;
  delete R_54;
  delete R_55;
  delete R_58;
  delete R_59;
  delete R_60;
  delete R_61;
  delete R_62;
  delete R_63;
  delete R_65;
  delete R_66;
  delete R_67;
  delete R_68;
  delete R_75;
  delete R_80;
  delete R_81;
  delete R_82;
  delete R_83;
  delete R_84;
  delete R_85;
  delete L_28;
  delete L_29;
  delete L_32;
  delete L_33;
  delete L_38;
  delete L_41;
  delete L_42;
  delete L_44;
  delete L_46;
  delete L_48;
  delete L_49;
  delete L_50;
  delete L_51;
  delete L_52;
  delete L_53;
  delete L_54;
  delete L_55;
  delete L_58;
  delete L_59;
  delete L_60;
  delete L_65;
  delete L_75;
  delete L_80;
  delete L_83;
}

//---------------------------------------------------------------------------
void __fastcall TGrvPH::LimpaTodas(void)
{
  Limpa(R_10);
  Limpa(R_20S);
  Limpa(R_20E);
  Limpa(R_21S);
  Limpa(R_21E);
  Limpa(R_22);
  Limpa(R_23S);
  Limpa(R_23E);
  Limpa(R_24);
  Limpa(R_25);
  Limpa(R_26);
  Limpa(R_27);
  Limpa(R_28);
  Limpa(R_29);
  Limpa(R_30);
  Limpa(R_31);
  Limpa(R_32);
  Limpa(R_33);
  Limpa(R_34);
  Limpa(R_35);
  Limpa(R_36S);
  Limpa(R_36E);
  Limpa(R_37);
  Limpa(R_38);
  Limpa(R_41);
  Limpa(R_42);
  Limpa(R_44);
  Limpa(R_45);
  Limpa(R_46);
  Limpa(R_47);
  Limpa(R_47R);
  Limpa(R_47AQ);
  Limpa(R_47AE);
  Limpa(R_47M);
  Limpa(R_48);
  Limpa(R_49,true);
  Limpa(R_50);
  Limpa(R_51);
  Limpa(R_52);
  Limpa(R_53);
  Limpa(R_54);
  Limpa(R_55);
  Limpa(R_58);
  Limpa(R_59);
  Limpa(R_60);
  Limpa(R_61);
  Limpa(R_63);
  Limpa(R_62);
  Limpa(R_65);
  Limpa(R_66);
  Limpa(R_67);
  Limpa(R_68);
  Limpa(R_75);
  Limpa(R_80);
  Limpa(R_81);
  Limpa(R_82);
  Limpa(R_83);
  Limpa(R_84);
  Limpa(R_85);
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::AbreArquivo(AnsiString Arquivo)
{
  _rtl_close(_rtl_creat(Arquivo.c_str(), FA_ARCH));
  W = fopen(Arquivo.c_str(),"w+");
  if(W == NULL)
   throw Exception("Erro abrindo arquivo destino.");
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::FechaArquivo(void)
{
  fclose(W);
}

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GravaRegistros(void)
{
  GrvPH(R_10);
  GrvPH(R_20S);
  GrvPH(R_20E);
  GrvPH(R_21S);
  GrvPH(R_21E);
  GrvPH(R_22);
  GrvPH(R_23S);
  GrvPH(R_23E);
  GrvPH(R_24);
  GrvPH(R_25);
  GrvPH(R_26);
  GrvPH(R_27);
  GrvPH_28();
  GrvPH_29();
  GrvPH(R_30);
  GrvPH(R_31);
  GrvPH_32();
  GrvPH_33();
  GrvPH(R_34);
  GrvPH(R_35);
  GrvPH(R_36S);
  GrvPH(R_36E);
  GrvPH(R_37);
  GrvPH_38();
  GrvPH_41();
  GrvPH_42();
  GrvPH_44();
  GrvPH(R_45);
  GrvPH_46();
  GrvPH(R_47);
  GrvPH(R_47R);
  GrvPH_48();
  GrvPH_49();
  GrvPH_50();
  GrvPH_51();
  GrvPH_52();
  GrvPH_53();
  GrvPH_54();
  GrvPH_55();
  GrvPH_58();
  GrvPH_59();
  GrvPH_60();
  GrvPH_75();
  GrvPH_80();
  GrvPH_83();
};

//---------------------------------------------------------------------------
AnsiString __fastcall TGrvPH::AjustaNumerico(double Valor, int Decimais)
{
  AnsiString Retorno = "";
  AnsiString S = Redondo(Valor,Decimais);
  for(int i = 1; i <= S.Length(); i++)
   if(S[i] == '.')
    Retorno += "";
   else
    Retorno += S[i];
  return(Retorno);
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Reg90(void)
{
  if(Contador>0)
   {
    Contador++;
    Fpr(W,"90");
    Fpr(W,"%05.5d",Contador);
    Fpr(W,"%249s"," ");
    Fpr(W,"\n");
   }
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH(struct REGISTRO_10 *R)
{
  if(!Contador)
   {
    Fpr(W,"10");
    Fpr(W,"%14.14s",R->CNPJ.c_str());
    Fpr(W,"%-15.15s",R->IE.c_str());
    Fpr(W,"%06.6d",R->MES_ANO);
    Fpr(W,"%219s"," ");
    Fpr(W,"\n");
    Contador++;
   }
  Limpa(R);
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH(struct REGISTRO_20S *R)
{
  if(!R->GRAVAR)
   return;
  Fpr(W,"20");
  Fpr(W,"%02.2d",R->DIA);
  Fpr(W,"%-5.5s",R->ESPECIE.c_str());
  Fpr(W,"%-5.5s",R->SERIE.c_str());
  Fpr(W,"%06.6d",R->DOCUMENTO);
  Fpr(W,"%06.6d",R->SEQUENCIA);
  Fpr(W,"%2.2s",R->ESTADO.c_str());
  Fpr(W,"%04.4d",R->CFOP);
  Fpr(W,"%04.4d",R->HISTORICO);
  Fpr(W,"%-25.25s",R->MUN_ORIGEM.c_str());
  Fpr(W,"%-24.24s",R->OBS.c_str());
  Fpr(W,"%1.1s",R->MOD_DOCUMENTO.c_str());
  Fpr(W,"%01.1d",R->MOD_FRETE);
  Fpr(W,"%01.1d",R->SAIDA_EXP);
  Fpr(W,"%01.1d",R->SITUACAO_DOC);
  Fpr(W,"%02.2d",R->SUB_CODIGO);
  Fpr(W,"%01.1d",R->AGRUPAR_LCTO);
  Fpr(W,"%1.1s",R->DOC_ELETRONICO.c_str());
  Fpr(W,"%44.44s",R->CHAVE.c_str());
  Fpr(W,"%8.8s",DataStr(R->DT_SAIDA).c_str());
  Fpr(W,"%-76.76s",R->COMPLEMENTO.c_str());
  Fpr(W,"%-20.20s",R->DOC_CANCELADOS.c_str());
  Fpr(W,"%01.1d",R->TIPO_FATURA);
  Fpr(W,"%14s"," ");
  Fpr(W,"\n");
  Contador++;
  Limpa(R);
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH(struct REGISTRO_20E *R)
{
  if(!R->GRAVAR)
   return;
  Fpr(W,"20");
  Fpr(W,"%02.2d",R->DIA);
  Fpr(W,"%8.8s",DataStr(R->DT_DOCUMENTO).c_str());
  Fpr(W,"%-5.5s",R->ESPECIE.c_str());
  Fpr(W,"%-5.5s",R->SERIE.c_str());
  Fpr(W,"%06.6d",R->DOCUMENTO);
  Fpr(W,"%04.4d",R->CFOP);
  Fpr(W,"%04.4d",R->HISTORICO);
  Fpr(W,"%-25.25s",R->OBS.c_str());
  Fpr(W,"%1.1s",R->MOD_DOCUMENTO.c_str());
  Fpr(W,"%01.1d",R->MOD_FRETE);
  Fpr(W,"%01.1d",R->SITUACAO_DOC);
  Fpr(W,"%02.2d",R->SUB_CODIGO);
  Fpr(W,"%1.1s",R->INDICADOR.c_str());
  Fpr(W,"%1.1s",R->EXEC_FORA.c_str());
  Fpr(W,"%1.1s",R->EXEC_TERCEIROS.c_str());
  Fpr(W,"%10.10s",R->COD_ATIVIDADE.c_str());
  Fpr(W,"%01.1d",R->TIPO_NF);
  Fpr(W,"%1.1s",R->DOC_ELETRONICO.c_str());
  Fpr(W,"%44.44s",R->CHAVE.c_str());
  Fpr(W,"%-75.75s",R->COMPLEMENTO.c_str());
  Fpr(W,"%4s"," ");
  Fpr(W,"%01.1d",R->TIPO_FATURA);
  Fpr(W,"%51s"," ");
  Fpr(W,"\n");
  Contador++;
  Limpa(R);
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH(struct REGISTRO_21S *R)
{
  if(!R->GRAVAR)
   return;
  Fpr(W,"21");
  Fpr(W,"%-12.12s",AjustaNumerico(R->VALOR,2));
  Fpr(W,"%-9.9s",AjustaNumerico(R->FRETE,2));
  Fpr(W,"%-9.9s",AjustaNumerico(R->SEGURO,2));
  Fpr(W,"%-9.9s",AjustaNumerico(R->OUTRAS,2));
  Fpr(W,"%-9.9s",AjustaNumerico(R->DESCONTO,2));
  Fpr(W,"%-9.9s",AjustaNumerico(R->BASE_IRPJ[0],2));
  Fpr(W,"%-4.4s",AjustaNumerico(R->ALIQUOTA[0],2));
  Fpr(W,"%-9.9s",AjustaNumerico(R->BASE_IRPJ[1],2));
  Fpr(W,"%-4.4s",AjustaNumerico(R->ALIQUOTA[1],2));
  Fpr(W,"%-9.9s",AjustaNumerico(R->BASE_IRPJ[2],2));
  Fpr(W,"%-4.4s",AjustaNumerico(R->ALIQUOTA[2],2));
  Fpr(W,"%-9.9s",AjustaNumerico(R->BASE_IRPJ[3],2));
  Fpr(W,"%-4.4s",AjustaNumerico(R->ALIQUOTA[3],2));
  Fpr(W,"%-9.9s",AjustaNumerico(R->BASE_IRPJ[4],2));
  Fpr(W,"%-4.4s",AjustaNumerico(R->ALIQUOTA[4],2));
  Fpr(W,"%-9.9s",AjustaNumerico(R->DEDUCAO,2));
  Fpr(W,"%-9.9s",AjustaNumerico(R->VL_CONTABIL[0],2));
  Fpr(W,"%-9.9s",AjustaNumerico(R->VL_CONTABIL[1],2));
  Fpr(W,"%-9.9s",AjustaNumerico(R->VL_CONTABIL[2],2));
  Fpr(W,"%-9.9s",AjustaNumerico(R->VL_CONTABIL[3],2));
  Fpr(W,"%-9.9s",AjustaNumerico(R->VL_CONTABIL[4],2));
  Fpr(W,"%-9.9s",AjustaNumerico(R->PIS_COFINS,2));
  Fpr(W,"%-9.9s",AjustaNumerico(R->APROP_CRED,2));
  Fpr(W,"%-9.9s",AjustaNumerico(R->RESSARC_ST,2));
  Fpr(W,"%-9.9s",AjustaNumerico(R->TRANSF_CREDITO,2));
  Fpr(W,"%-9.9s",AjustaNumerico(R->VL_COMPLE,2));
  Fpr(W,"%-9.9s",AjustaNumerico(R->SERVICO_NT,2));
  Fpr(W,"%03.3d",R->CC_DEBITO);
  Fpr(W,"%03.3d",R->CC_CREDITO);
  Fpr(W,"%27s"," ");
  Fpr(W,"\n");
  Contador++;
  Limpa(R);
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH(struct REGISTRO_21E *R)
{
  if(!R->GRAVAR)
   return;
  Fpr(W,"21");
  Fpr(W,"%-12.12s",AjustaNumerico(R->VALOR,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->FRETE,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->SEGURO,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->OUTRAS,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->DESCONTO,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->FUNRURAL,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->BC_ICMS_SR,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->ICMS_SR,2));
  Fpr(W,"%01.1d",R->COD_ICMSST);
  Fpr(W,"%1.1s",R->TIPO_ICMSSR.c_str());
  Fpr(W,"%-12.12s",AjustaNumerico(R->VL_CONTABIL[0],2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->VL_CONTABIL[1],2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->VL_CONTABIL[2],2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->VL_CONTABIL[3],2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->VL_CONTABIL[4],2));
  Fpr(W,"%-9.9s",AjustaNumerico(R->PIS_COFINS,2));
  Fpr(W,"%-9.9s",AjustaNumerico(R->APROP_CRED,2));
  Fpr(W,"%-9.9s",AjustaNumerico(R->RESSARC_ST,2));
  Fpr(W,"%-9.9s",AjustaNumerico(R->TRANSF_CREDITO,2));
  Fpr(W,"%-9.9s",AjustaNumerico(R->VALOR_COMPLE,2));
  Fpr(W,"%-9.9s",AjustaNumerico(R->SERVICO_NT,2));
  Fpr(W,"%03.3d",R->CC_DEBITO);
  Fpr(W,"%03.3d",R->CC_CREDITO);
  Fpr(W,"%36s"," ");
  Fpr(W,"\n");
  Contador++;
  Limpa(R);
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH(struct REGISTRO_22 *R)
{
  if(!R->GRAVAR)
   return;
  Fpr(W,"22");
  Fpr(W,"%-40.40s",R->NOME.c_str());
  Fpr(W,"%-18.18s",R->INSCRICAO.c_str());
  Fpr(W,"%01.1d",R->TIPO_INSC);
  Fpr(W,"%-14.14s",R->IE.c_str());
  Fpr(W,"%-40.40s",R->ENDERECO.c_str());
  Fpr(W,"%-14.14s",R->BAIRRO.c_str());
  Fpr(W,"%-9.9s",R->CEP.c_str());
  Fpr(W,"%2.2s",R->ESTADO.c_str());
  Fpr(W,"%-25.25s",R->MUNICIPIO.c_str());
  Fpr(W,"%08.8d",R->CCD_CONTABIL);
  Fpr(W,"%12.12s",R->CEI_NIT.c_str());
  Fpr(W,"%14.14s",R->IM.c_str());
  Fpr(W,"%11.11s",R->TELEFONE.c_str());
  Fpr(W,"%-40.40s",R->NOME_FANT.c_str());
  Fpr(W,"%-4.4s",R->PAIS.c_str());
  Fpr(W,"%2s"," ");
  Fpr(W,"\n");
  Contador++;
  Limpa(R);
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH(struct REGISTRO_23S *R)
{
  if(!R->GRAVAR)
   return;
  Fpr(W,"23");
  Fpr(W,"%-12.12s",AjustaNumerico(R->BASE_CALCULO[0],2));
  Fpr(W,"%-4.4s",AjustaNumerico(R->ALIQUOTA[0],2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->VALOR_ICMS[0],2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->BASE_CALCULO[1],2));
  Fpr(W,"%-4.4s",AjustaNumerico(R->ALIQUOTA[1],2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->VALOR_ICMS[1],2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->BASE_CALCULO[2],2));
  Fpr(W,"%-4.4s",AjustaNumerico(R->ALIQUOTA[2],2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->VALOR_ICMS[2],2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->BASE_CALCULO[3],2));
  Fpr(W,"%-4.4s",AjustaNumerico(R->ALIQUOTA[3],2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->VALOR_ICMS[3],2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->BASE_CALCULO[4],2));
  Fpr(W,"%-4.4s",AjustaNumerico(R->ALIQUOTA[4],2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->VALOR_ICMS[4],2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->ISENTAS,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->OUTRAS,2));
  Fpr(W,"%90s"," ");
  Fpr(W,"\n");
  Contador++;
  Limpa(R);
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH(struct REGISTRO_23E *R)
{
  if(!R->GRAVAR)
   return;
  Fpr(W,"23");
  Fpr(W,"%-12.12s",AjustaNumerico(R->BASE_CALCULO[0],2));
  Fpr(W,"%-4.4s",AjustaNumerico(R->ALIQUOTA[0],2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->VALOR_ICMS[0],2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->BASE_CALCULO[1],2));
  Fpr(W,"%-4.4s",AjustaNumerico(R->ALIQUOTA[1],2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->VALOR_ICMS[1],2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->BASE_CALCULO[2],2));
  Fpr(W,"%-4.4s",AjustaNumerico(R->ALIQUOTA[2],2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->VALOR_ICMS[2],2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->BASE_CALCULO[3],2));
  Fpr(W,"%-4.4s",AjustaNumerico(R->ALIQUOTA[3],2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->VALOR_ICMS[3],2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->BASE_CALCULO[4],2));
  Fpr(W,"%-4.4s",AjustaNumerico(R->ALIQUOTA[4],2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->VALOR_ICMS[4],2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->ISENTAS,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->OUTRAS,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->BC_DIF_ALIQ_ICMS,2));
  Fpr(W,"%-4.4s",AjustaNumerico(R->ALIQ_DIF_ICMS,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->VL_DIF_ALIQ_ICMS,2));
  Fpr(W,"%01.1d",R->TIP_DIF_ALIQ_ICMS);
  Fpr(W,"%01.1d",R->TIP_LCTO);
  Fpr(W,"%01.1d",R->APURACAO);
  Fpr(W,"%-12.12s",AjustaNumerico(R->BC_ICMS_DCIP,2));
  Fpr(W,"%-4.4s",AjustaNumerico(R->ALIQ_ICMS_DCIP,2));
  Fpr(W,"%43s"," ");
  Fpr(W,"\n");
  Contador++;
  Limpa(R);
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH(struct REGISTRO_24 *R)
{
  if(!R->GRAVAR)
   return;
  Fpr(W,"24");
  Fpr(W,"%03.3d",R->NUM_EQUIP);
  Fpr(W,"%-20.20s",R->NUM_SERIE.c_str());
  Fpr(W,"%06.6d",R->NUM_REDUCAOZ);
  Fpr(W,"%-16.16s",AjustaNumerico(R->INICIO_DIA,2));
  Fpr(W,"%03.3d",R->CRO);
  Fpr(W,"%-16.16s",AjustaNumerico(R->FINAL_DIA,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->OPERACOES_ST,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->ISENTAS,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->NAO_INCIDENCIA,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->CANCELAMENTOS,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->DESCONTOS,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->ISSQN,2));
  Fpr(W,"%06.6d",R->NUM_INICIAL);
  Fpr(W,"%06.6d",R->NUM_FINAL);
  Fpr(W,"%-12.12s",AjustaNumerico(R->VL_VISTA,2));
  Fpr(W,"%-20.20s",R->MOD_EQUIPAMENTO.c_str());
  Fpr(W,"%-8.8s",AjustaNumerico(R->ACRESCIMOS,2));
  Fpr(W,"%-8.8s",AjustaNumerico(R->CANC_ISS,2));
  Fpr(W,"%-8.8s",AjustaNumerico(R->DESC_ISS,2));
  Fpr(W,"%-8.8s",AjustaNumerico(R->ACRES_ISS,2));
  Fpr(W,"%-8.8s",AjustaNumerico(R->OPER_NAOFISCAIS,2));
  Fpr(W,"%-8.8s",AjustaNumerico(R->CANC_NAOFISCAIS,2));
  Fpr(W,"%-8.8s",AjustaNumerico(R->DESC_NAOFISCAIS,2));
  Fpr(W,"%-8.8s",AjustaNumerico(R->ACRES_NAOFISCAIS,2));
  Fpr(W,"%-8.8s",AjustaNumerico(R->IOF,2));
  Fpr(W,"%2s"," ");
  Fpr(W,"\n");
  Contador++;
  Limpa(R);
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH(struct REGISTRO_25 *R)
{
  if(!R->GRAVAR)
   return;
  Fpr(W,"25");
  Fpr(W,"%-12.12s",AjustaNumerico(R->BASE_CALCULO,2));
  Fpr(W,"%-5.5s",AjustaNumerico(R->ALIQUOTA,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->IPI,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->ISENTAS,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->OUTRAS,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->TOTALIPI,2));
  Fpr(W,"%189s"," ");
  Fpr(W,"\n");
  Contador++;
  Limpa(R);
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH(struct REGISTRO_26 *R)
{
  if(!R->GRAVAR)
   return;
  Fpr(W,"26");
  Fpr(W,"%-12.12s",AjustaNumerico(R->BASE_CALCULO,2));
  Fpr(W,"%-4.4s",AjustaNumerico(R->ALIQUOTA,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->ISS,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->IMPOSTO_RETIDO,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->ISENTAS_OUTRAS,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->SUBST_TRIB,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->MAT_APLICADOS,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->SUB_EMPREITADAS,2));
  Fpr(W,"%-30.30s",R->OBS.c_str());
  Fpr(W,"%1.1s",R->EXEC_FORAMUN.c_str());
  Fpr(W,"%1.1s",R->EXEC_BTERC.c_str());
  Fpr(W,"%1.1s",R->RETENCAO.c_str());
  Fpr(W,"%07.7d",R->COD_MUN);
  Fpr(W,"%01.1d",R->SITUACAO_NF);
  Fpr(W,"%125s"," ");
  Fpr(W,"\n");
  Contador++;
  Limpa(R);
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH(struct REGISTRO_27 *R)
{
  if(!R->GRAVAR)
   return;
  Fpr(W,"27");
  Fpr(W,"%-12.12s",AjustaNumerico(R->BASE_CALCULO,2));
  Fpr(W,"%-4.4s",AjustaNumerico(R->ALIQUOTA,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->VALOR,2));
  Fpr(W,"%01.1d",R->TIPO_LTCO);
  Fpr(W,"%01.1d",R->APURACAO);
  Fpr(W,"%224s"," ");
  Fpr(W,"\n");
  Contador++;
  Limpa(R);
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH_28(void)
{
  struct REGISTRO_28 *R;
  for(int i=0;i<L_28->Count;i++)
   {
    R = (struct REGISTRO_28 *)L_28->Items[i];
    Fpr(W,"28");
    Fpr(W,"%02.2d",R->CODIGO);
    Fpr(W,"%-12.12s",AjustaNumerico(R->VALOR,2));
    Fpr(W,"%240s"," ");
    Fpr(W,"\n");
    Contador++;
    Limpa(R);
   }
  L_28->Clear();
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH_29(void)
{
  struct REGISTRO_29 *R;
  for(int i=0;i<L_29->Count;i++)
   {
    R = (struct REGISTRO_29 *)L_29->Items[i];
    Fpr(W,"29");
    Fpr(W,"%-10.10s",R->CLASSIF_FISCAL.c_str());
    Fpr(W,"%-40.40s",R->DESCRICAO.c_str());
    Fpr(W,"%-6.6s",R->UNIDADE.c_str());
    Fpr(W,"%01.1s",R->PRODUTO.c_str());
    Fpr(W,"%-14.14s",R->CODIGO.c_str());
    Fpr(W,"%-13.13s",AjustaNumerico(R->QUANTIDADE,3));
    Fpr(W,"%-12.12s",AjustaNumerico(R->VL_TOTAL,2));
    Fpr(W,"%-12.12s",AjustaNumerico(R->VL_DESC,2));
    Fpr(W,"%03.3d",R->COD_SITUACAOTRIB);
    Fpr(W,"%-12.12s",AjustaNumerico(R->BASE_ICMS,2));
    Fpr(W,"%-4.4s",AjustaNumerico(R->REDUCAO_BICMS,2));
    Fpr(W,"%-4.4s",AjustaNumerico(R->ALIQ_ICMSCALC,2));
    Fpr(W,"%-4.4s",AjustaNumerico(R->ALiQ_ICMSINT,2));
    Fpr(W,"%-12.12s",AjustaNumerico(R->BC_ICMS_ST,2));
    Fpr(W,"%-12.12s",AjustaNumerico(R->VL_UNICMS_ST,2));
    Fpr(W,"%-4.4s",AjustaNumerico(R->ALIQ_IPI,2));
    Fpr(W,"%-12.12s",AjustaNumerico(R->VL_IPI,2));
    Fpr(W,"%1.1d",R->IND_IPI);
    Fpr(W,"%-12.12s",AjustaNumerico(R->VL_ICMS_ST,2));
    Fpr(W,"%1.1s",R->MOV_FISICA.c_str());
    Fpr(W,"%-20.20s",R->NUM_SERIE.c_str());
    Fpr(W,"%1.1d",R->TIPO_INFO);
    Fpr(W,"%03.3d",R->CST_PREPOND);
    Fpr(W,"%41s"," ");
    Fpr(W,"\n");
    Contador++;
    Limpa(R);
  }
  L_29->Clear();
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH(struct REGISTRO_30 *R)
{
  if(!R->GRAVAR)
   return;
  Fpr(W,"30");
  Fpr(W,"%-35.35s",R->TRANSPORTADOR.c_str());
  Fpr(W,"%-14.14s",R->INSCRICAO.c_str());
  Fpr(W,"%1.1d",R->TIPO_INSCR);
  Fpr(W,"%-14.14s",R->IE.c_str());
  Fpr(W,"%-32.32s",R->ENDERECO.c_str());
  Fpr(W,"%-14.14s",R->BAIRRO.c_str());
  Fpr(W,"%8.8s",R->CEP.c_str());
  Fpr(W,"%2.2s",R->ESTADO.c_str());
  Fpr(W,"%-20.20s",R->MUNICIPIO.c_str());
  Fpr(W,"%-13.13s",R->VIA_TRANSPORTE.c_str());
  Fpr(W,"%7.7d",R->QTD_VOLUMES);
  Fpr(W,"%-8.8s",R->ESP_VOLUME.c_str());
  Fpr(W,"%-9.9s",AjustaNumerico(R->PESO_BRUTO,3).c_str());
  Fpr(W,"%-9.9s",AjustaNumerico(R->PESO_LIQUIDO,3).c_str());
  Fpr(W,"%01.1d",R->MOD_FRETE);
  Fpr(W,"%-12.12s",R->IDE_VEICULO.c_str());
  Fpr(W,"%1.1d",R->TIPO_FATURA);
  Fpr(W,"%-14.14s",R->IE_ST.c_str());
  Fpr(W,"%-40.40s",R->OBS.c_str());
  Fpr(W,"\n");
  Contador++;
  Limpa(R);
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH(struct REGISTRO_31 *R)
{
  if(!R->GRAVAR)
   return;
  Fpr(W,"31");
  Fpr(W,"%-9.9s",AjustaNumerico(R->MEDIC_PERF_HIG,2));
  Fpr(W,"%-9.9s",AjustaNumerico(R->COMBUST,2));
  Fpr(W,"%-9.9s",AjustaNumerico(R->VEICULOS[0],2));
  Fpr(W,"%-9.9s",AjustaNumerico(R->CIGARROS,2));
  Fpr(W,"%-9.9s",AjustaNumerico(R->ALIQ_BASE,2));
  Fpr(W,"%-9.9s",AjustaNumerico(R->ALIQ_DEV,2));
  Fpr(W,"%-9.9s",AjustaNumerico(R->ALIQ_AQUI,2));
  Fpr(W,"%-9.9s",AjustaNumerico(R->ALIQ_OUTRAS,2));
  Fpr(W,"%1.1d",R->TIPO_PRODUTO[0]);
  Fpr(W,"%-9.9s",AjustaNumerico(R->VEICULOS[1],2));
  Fpr(W,"%-9.9s",AjustaNumerico(R->PNEUS_CAM[0],2));
  Fpr(W,"%-9.9s",AjustaNumerico(R->VENDA_PARTES,2));
  Fpr(W,"%-9.9s",AjustaNumerico(R->PNEUS_CAM[1],2));
  Fpr(W,"%-9.9s",AjustaNumerico(R->DEVOL[0],2));
  Fpr(W,"%-9.9s",AjustaNumerico(R->OUTRAS_DED[0],2));
  Fpr(W,"%-9.9s",AjustaNumerico(R->VEICULOS[2],2));
  Fpr(W,"%-9.9s",AjustaNumerico(R->DEVOL[1],2));
  Fpr(W,"%-9.9s",AjustaNumerico(R->OUTRAS_DED[1],2));
  Fpr(W,"%-9.9s",AjustaNumerico(R->VENDAS_RED[0],2));
  Fpr(W,"%-9.9s",AjustaNumerico(R->VENDAS_RED[1],2));
  Fpr(W,"%-9.9s",AjustaNumerico(R->VL_CONCESS,2));
  Fpr(W,"%1.1d",R->TIPO_PRODUTO[1]);
  Fpr(W,"%-8.8s",AjustaNumerico(R->BEBIDAS,2));
  Fpr(W,"%-8.8s",AjustaNumerico(R->MP_EMBBEB,2));
  Fpr(W,"%-8.8s",AjustaNumerico(R->ALDIF_VENDABEB,2));
  Fpr(W,"%-8.8s",AjustaNumerico(R->ALDIF_DEVOLBEB,2));
  Fpr(W,"%-8.8s",AjustaNumerico(R->ALDIF_REVBEB,2));
  Fpr(W,"%-8.8s",AjustaNumerico(R->ALDIF_BEBEMB,2));
  Fpr(W,"%-8.8s",AjustaNumerico(R->ALDIF_AQUISCRED,2));
  Fpr(W,"%-8.8s",AjustaNumerico(R->ICMS_IPI,2));
  Fpr(W,"%-8.8s",AjustaNumerico(R->OUTROS_PRODUTOS,2));
  Fpr(W,"\n");
  Contador++;
  Limpa(R);
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH_32(void)
{
  struct REGISTRO_32 * R;
  for(int i=0;i<L_32->Count;i++)
   {
    R = (struct REGISTRO_32 *)L_32->Items[i];
    Fpr(W,"32");
    Fpr(W,"%2.2s",R->UF.c_str());
    Fpr(W,"%-14.14s",R->INSCRICAO.c_str());
    Fpr(W,"%-15.15s",R->IE.c_str());
    Fpr(W,"%8.8s",DataStr(R->DT_NF).c_str());
    Fpr(W,"%02.2d",R->MODELO);
    Fpr(W,"%2.2s",R->SERIE.c_str());
    Fpr(W,"%2.2s",R->SUB_SERIE.c_str());
    Fpr(W,"%6.6d",R->NUMERO);
    Fpr(W,"%-12.12s",AjustaNumerico(R->VALOR,2));
    Fpr(W,"%191s"," ");
    Fpr(W,"\n");
    Contador++;
    Limpa(R);
   }
  L_32->Clear();
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH_33(void)
{
  struct REGISTRO_33 *R;
  for(int i=0;i<L_33->Count;i++)
   {
    R = (struct REGISTRO_33 *)L_33->Items[i];
    Fpr(W,"33");
    Fpr(W,"%-45.45s",R->DESCRICAO.c_str());
    Fpr(W,"%-12.12s",AjustaNumerico(R->VALOR,2));
    Fpr(W,"%-12.12s",AjustaNumerico(R->VL_DESC,2));
    Fpr(W,"%-12.12s",AjustaNumerico(R->VL_MATERIAL,2));
    Fpr(W,"%-12.12s",AjustaNumerico(R->BASE_ISS,2));
    Fpr(W,"%-4.4s",AjustaNumerico(R->ALIQ_ISS,2));
    Fpr(W,"%-12.12s",AjustaNumerico(R->VL_ISS,2));
    Fpr(W,"%-12.12s",AjustaNumerico(R->BASE_RETINSS,2));
    Fpr(W,"%-4.4s",AjustaNumerico(R->ALIQ_RETINSS,2));
    Fpr(W,"%-12.12s",AjustaNumerico(R->VL_RETINSS,2));
    Fpr(W,"%-8.8s",R->COD_ATIVIDADE.c_str());
    Fpr(W,"%03.3d",R->CST);
    Fpr(W,"%-14.14s",R->COD_PROPRIO.c_str());
    Fpr(W,"%92s"," ");
    Fpr(W,"\n");
    Contador++;
    Limpa(R);
   }
  L_33->Clear();
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH(struct REGISTRO_34*R)
{
  if(!R->GRAVAR)
   return;
  Fpr(W,"34");
  Fpr(W,"%-12.12s",AjustaNumerico(R->RECEITA_CSLL[0],2));
  Fpr(W,"%-4.4s",AjustaNumerico(R->ALIQ_CSLL[0],2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->RECEITA_CSLL[1],2));
  Fpr(W,"%-4.4s",AjustaNumerico(R->ALIQ_CSLL[1],2));
  Fpr(W,"%222s"," ");
  Fpr(W,"\n");
  Contador++;
  Limpa(R);
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH(struct REGISTRO_35 *R)
{
  if(!R->GRAVAR)
   return;
  Fpr(W,"35");
  Fpr(W,"%-12.12s",AjustaNumerico(R->BC_IRF,2));
  Fpr(W,"%-5.5s",AjustaNumerico(R->ALIQ_IRF,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->VL_IRF,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->BC_INSS,2));
  Fpr(W,"%-5.5s",AjustaNumerico(R->ALIQ_INSS,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->VL_INSS,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->BC_ISS,2));
  Fpr(W,"%-5.5s",AjustaNumerico(R->ALIQ_ISS,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->VL_ISS,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->BC_CSLL,2));
  Fpr(W,"%-5.5s",AjustaNumerico(R->ALIQ_CSLL,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->VL_CSLL,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->BC_COFINS,2));
  Fpr(W,"%-5.5s",AjustaNumerico(R->ALIQ_COFINS,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->VL_COFINS,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->BC_PIS,2));
  Fpr(W,"%-5.5s",AjustaNumerico(R->ALIQ_PIS,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->VL_PIS,2));
  Fpr(W,"%01.1d",R->IRF_ENT);
  Fpr(W,"%79s"," ");
  Fpr(W,"\n");
  Contador++;
  Limpa(R);
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH(struct REGISTRO_36S *R)
{
  if(!R->GRAVAR)
   return;
  Fpr(W,"36");
  Fpr(W,"%-10.10s",AjustaNumerico(R->ESTORNO_CREDITOS,2));
  Fpr(W,"%244s"," ");
  Fpr(W,"\n");
  Contador++;
  Limpa(R);
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH(struct REGISTRO_36E *R)
{
  if(!R->GRAVAR)
   return;
  Fpr(W,"36");
  Fpr(W,"%-10.10s",AjustaNumerico(R->CRED_TOTAL,2));
  Fpr(W,"%-10.10s",AjustaNumerico(R->CRED_PROP,2));
  Fpr(W,"%-10.10s",AjustaNumerico(R->CRED_PRESTOTAL,2));
  Fpr(W,"%-10.10s",AjustaNumerico(R->CRED_PRESPROP,2));
  Fpr(W,"%214s"," ");
  Fpr(W,"\n");
  Contador++;
  Limpa(R);
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH(struct REGISTRO_37 *R)
{
  if(!R->GRAVAR)
   return;
  Fpr(W,"37");
  Fpr(W,"%-10.10s",AjustaNumerico(R->MERCADORIAS,2));
  Fpr(W,"%-10.10s",AjustaNumerico(R->MERC_IND,2));
  Fpr(W,"%-10.10s",AjustaNumerico(R->LOC_BENS_MOVEIS,2));

  for(int i=0;i<3;i++)
   Fpr(W,"%-10.10s",AjustaNumerico(R->SERVICOS[i],2));

  Fpr(W,"%-10.10s",AjustaNumerico(R->TRANSP_INTER,2));
  Fpr(W,"%-10.10s",AjustaNumerico(R->ESCR_CONTABEIS,2));

  for(int i=0;i<3;i++)
   Fpr(W,"%-10.10s",AjustaNumerico(R->ST_REV_MERC[i],2));

  for(int i=0;i<3;i++)
   Fpr(W,"%-10.10s",AjustaNumerico(R->ST_MERC[i],2));

  Fpr(W,"%-10.10s",R->RESERVADO[0].c_str());
  Fpr(W,"%-10.10s",R->RESERVADO[1].c_str());

  for(int i=0;i<3;i++)
   Fpr(W,"%-10.10s",AjustaNumerico(R->ISS_ST[i],2));

  Fpr(W,"%-10.10s",R->RESERVADO[2].c_str());
  Fpr(W,"%-10.10s",R->RESERVADO[3].c_str());
  Fpr(W,"%44s"," ");
  Fpr(W,"\n");
  Contador++;
  Limpa(R);
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH_38(void)
{
  struct REGISTRO_38 *R;
  for(int i=0;i<L_38->Count;i++)
   {
    R = (struct REGISTRO_38 *)L_38->Items[i];
    Fpr(W,"38");
    Fpr(W,"%02.2d",R->IND_TIT);
    Fpr(W,"%-10.10s",R->DESC_TIT.c_str());
    Fpr(W,"%-10.10s",R->NUM_TIT.c_str());
    Fpr(W,"%8.8s",DataStr(R->DT_VCTO).c_str());
    Fpr(W,"%-10.10s",AjustaNumerico(R->VL_PARC,2));
    Fpr(W,"%214s"," ");
    Fpr(W,"\n");
    Contador++;
    Limpa(R);
   }
  L_38->Clear();
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH_41(void)
{
  struct REGISTRO_41 *R;
  for(int i=0;i<L_41->Count;i++)
   {
    R = (struct REGISTRO_41 *)L_41->Items[i];
    Fpr(W,"41");
    Fpr(W,"%7.7d",R->COD_MUN_ORIG);
    Fpr(W,"%-12.12s",AjustaNumerico(R->VL_SERV,2));
    Fpr(W,"%10.10d",R->QTDE_BILHETES);
    Fpr(W,"%-12.12s",AjustaNumerico(R->VL_BC_ICMS,2));
    Fpr(W,"%-12.12s",AjustaNumerico(R->VL_ICMS,2));
    Fpr(W,"%201s"," ");
    Fpr(W,"\n");
    Contador++;
    Limpa(R);
   }
  L_41->Clear();
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH_42(void)
{
  struct REGISTRO_42 *R;
  for(int i=0;i<L_42->Count;i++)
   {
    R = (struct REGISTRO_42 *)L_42->Items[i];
    Fpr(W,"42");
    Fpr(W,"%2.2s",R->COD_MOD.c_str());
    Fpr(W,"%5.5.s",R->SERIE.c_str());
    Fpr(W,"%9.9d",R->NUM_DOC_INI);
    Fpr(W,"%9.9d",R->NUM_DOC_FIN);
    Fpr(W,"%8.8s",DataStr(R->DT_DOC).c_str());
    Fpr(W,"%3.3d",R->CST_ICMS);
    Fpr(W,"%4.4d",R->CFOP);
    Fpr(W,"%-5.5s",AjustaNumerico(R->ALIQ_ICMS,2));
    Fpr(W,"%-12.12s",AjustaNumerico(R->ACUMULADO,2));
    Fpr(W,"%-12.12s",AjustaNumerico(R->DESCONTOS,2));
    Fpr(W,"%-12.12s",AjustaNumerico(R->PREST_SERV,2));
    Fpr(W,"%-12.12s",AjustaNumerico(R->BC_ICMS,2));
    Fpr(W,"%-12.12s",AjustaNumerico(R->VL_ICMS,2));
    Fpr(W,"%50.50s",R->CANCEL);
    Fpr(W,"%94s"," ");
    Fpr(W,"\n");
    Contador++;
    Limpa(R);
   }
  L_42->Clear();
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH_44(void)
{
  struct REGISTRO_44 *R;
  for(int i=0;i<L_44->Count;i++)
   {
    R = (struct REGISTRO_44 *)L_44->Items[i];
    Fpr(W,"44");
    Fpr(W,"%-40.40s",R->NOME.c_str());
    Fpr(W,"%-18.18s",R->INSCRICAO.c_str());
    Fpr(W,"%01.1d",R->TIPO_INSC);
    Fpr(W,"%-14.14s",R->IE.c_str());
    Fpr(W,"%-40.40s",R->ENDERECO.c_str());
    Fpr(W,"%-14.14s",R->BAIRRO.c_str());
    Fpr(W,"%-9.9s",R->CEP.c_str());
    Fpr(W,"%-2.2s",R->ESTADO.c_str());
    Fpr(W,"%-25.25s",R->MUNICIPIO.c_str());
    Fpr(W,"%08.8d",R->CCD_CONTABIL);
    Fpr(W,"%-12.12s",R->CEI_NIT.c_str());
    Fpr(W,"%-14.14s",R->IM.c_str());
    Fpr(W,"%-11.11s",R->TELEFONE.c_str());
    Fpr(W,"%-40.40s",R->NOME_FANT.c_str());
    Fpr(W,"%-4.4s",R->PAIS.c_str());    
    Fpr(W,"%2s"," ");
    Fpr(W,"\n");
    Contador++;
    Limpa(R);
   }
  L_44->Clear();
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH(struct REGISTRO_45 *R)
{
  if(!R->GRAVAR)
   return;
  Fpr(W,"45");
  Fpr(W,"%02.2d",R->COD_CLASSE);
  Fpr(W,"%06.6d",R->QTDE_DOC_CONSOL);
  Fpr(W,"%-50.50s",R->DOC_CANC.c_str());
  Fpr(W,"%12.12s",R->CONSUMO_TOTAL.c_str());
  Fpr(W,"%8.8s",DataStr(R->DT_EMI_INI).c_str());
  Fpr(W,"%8.8s",DataStr(R->DT_EMI_FIN).c_str());
  Fpr(W,"%15.15s",R->NOME_ARQ_MESTRE.c_str());
  Fpr(W,"%32.32s",R->CHAVE_ARQ_MESTRE.c_str());
  for(int i=0;i<5;i++)
   {
    Fpr(W,"%2.2s",R->UF_ICMS_ST[i].c_str());
    if(R->BC_ICMS_ST[i] > 0.0099)
     {
      Fpr(W,"%-10.10s",AjustaNumerico(R->BC_ICMS_ST[i],2));
      Fpr(W,"%-10.10s",AjustaNumerico(R->VL_ICMS_ST[i],2));
     }
    else
     {
      Fpr(W,"%10s","");
      Fpr(W,"%10s","");
     }
   }
  Fpr(W,"%01.1d",R->COD_TPLIGACAO);
  Fpr(W,"%02.2d",R->COD_GRTENSAO);
  Fpr(W,"%02.2d",R->COD_TPASSINANTE);
  Fpr(W,"%6s"," ");
  Fpr(W,"\n");
  Contador++;
  Limpa(R);
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH_46(void)
{
  struct REGISTRO_46 *R;
  for(int i=0;i<L_46->Count;i++)
   {
    R = (struct REGISTRO_46 *)L_46->Items[i];
    Fpr(W,"46");
    Fpr(W,"%01.1d",R->IND_SERV);
    Fpr(W,"%8.8s",DataStr(R->DT_INI_SERV).c_str());
    Fpr(W,"%8.8s",DataStr(R->DT_FIN_SERV).c_str());
    Fpr(W,"%6.6d",R->PER_FISCAL);
    Fpr(W,"%-10.10s",R->COD_AREA.c_str());
    Fpr(W,"%-20.20s",R->TERMINAL.c_str());
    Fpr(W,"%201s"," ");
    Fpr(W,"\n");
    Contador++;
    Limpa(R);
   }
  L_46->Clear();
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH(struct REGISTRO_47 *R)
{
  if(!R->GRAVAR)
   return;
  Fpr(W,"47");
  Fpr(W,"%01.1d",R->TIPO_CTE);
  Fpr(W,"%-44.44s",R->CHAVE_CTE.c_str());
  Fpr(W,"%07.7d",StrToIntDef(R->COD_MUN_DEST,0));
  Fpr(W,"%-40.40s",R->RESERVADO[0].c_str());
  Fpr(W,"%-2.2s",R->RESERVADO[1].c_str());
  Fpr(W,"%8.8s",R->PLACA.c_str());
  Fpr(W,"%2.2s",R->UF_PLACA.c_str());
  Fpr(W,"%-14.14s",R->INSCR_CONSIG.c_str());
  Fpr(W,"%-14.14s",R->INSCR_REDESP.c_str());
  Fpr(W,"%01.1d",R->IND_REDESP);
  Contador++;
  Limpa(R);
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH(struct REGISTRO_47R *R)
{
  if(!R->GRAVAR)
   return;
  Fpr(W,"%-12.12s",AjustaNumerico(R->SEC_CAT,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->VL_DESPACHO,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->VL_PEDAGIO,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->VL_OUTROS,2));
  Fpr(W,"%-73s"," ");
  Fpr(W,"\n");
  Limpa(R);
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH(struct REGISTRO_47AQ *R)
{
/*if(!R->GRAVAR)
   return;
   AnsiString teste = "";
  Fpr(W,"%01.1d",R->TIPO_VEICULO);
  Fpr(W,"%-16.16s",R->IDE_EMBARC.c_str());
  Fpr(W,"%01.1d",R->TIPO_NAVEG);
  Fpr(W,"%08.8d",R->NUM_VIAGEM);
  Fpr(W,"%-12.12s",AjustaNumerico(R->DESP_PORTUARIAS,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->DESP_CARG_DESCARGA,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->VL_OUTROS,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->VL_ADIC_FRETE,2));
  Fpr(W,"%47s"," ");
  Fpr(W,"\n");
  Limpa(R);*/
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH(struct REGISTRO_47AE *R)
{
/*if(!R->GRAVAR)
   return;
  Fpr(W,"%-30.30s",R->IDE_AERONAVE.c_str());
  Fpr(W,"%08.8d",R->NUM_VOO);
  Fpr(W,"%01.1d",R->TIPO_TARIFA);
  Fpr(W,"%-8.8s",AjustaNumerico(R->PESO_TAXADO,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->TAXA_TERRESTRE,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->TAXA_REDESPACHO,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->VL_OUTROS,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->TAXA_ADVALOREM,2));
  Fpr(W,"%26s"," ");
  Fpr(W,"\n");
  Limpa(R);*/
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH(struct REGISTRO_47M *R)
{
/*/f(!R->GRAVAR)
   return;
  Fpr(W,"%-20.20s",R->REG_OPERADOR.c_str());
  Fpr(W,"%01.1d",R->NAT_FRETE);
  Fpr(W,"%-12.12s",AjustaNumerico(R->GER_RISCO,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->PEDAGIO,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->VL_OUTROS,2));
  Fpr(W,"%64s"," ");
  Fpr(W,"\n");
  Limpa(R);  */
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH_48(void)
{
/*  struct REGISTRO_48 *R;
  for(int i=0;i<L_48->Count;i++)
   {
    R = (struct REGISTRO_48 *)L_48->Items[i];
    Fpr(W,"48");
    Fpr(W,"%01.1d",R->IND_EMIT);
    Fpr(W,"%-14.14s",R->CNPJ_CPF_EMIT.c_str());
    Fpr(W,"%2.2s",R->UF_EMIT.c_str());
    Fpr(W,"%-14.14s",R->IE_EMIT.c_str());
    Fpr(W,"%07.7d",R->COD_MUN_ORIG);
    Fpr(W,"%-14.14s",R->IE_TOM.c_str());
    Fpr(W,"%2.2s",R->UF_TOM.c_str());
    Fpr(W,"%-14.14s",R->IE_TOM.c_str());
    Fpr(W,"%07.7d",R->COD_MUN_DEST);
    Fpr(W,"%2.2s",R->COD_MOD.c_str());
    Fpr(W,"%5.5s",R->SER.c_str());
    Fpr(W,"%5.5s",R->SUB.c_str());
    Fpr(W,"%9.9d",R->NUM_DOC);
    Fpr(W,"%8.8s",DataStr(R->DT_DOC).c_str());
    Fpr(W,"%-12.12s",AjustaNumerico(R->VL_DOC,2));
    Fpr(W,"%138s"," ");
    Fpr(W,"\n");
    Contador++;
    Limpa(R);
   }
  L_48->Clear();*/
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH_49(void)
{
  struct REGISTRO_49 *R;
  for(int i=0;i<L_49->Count;i++)
   {
    R = (struct REGISTRO_49 *)L_49->Items[i];
    Fpr(W,"49");
    Fpr(W,"%12.12s",R->DESPACHO.c_str());
    Fpr(W,"%-14.14s",R->CNPJ_CPF_REM.c_str());
    Fpr(W,"%-14.14s",R->IE_REM.c_str());
    Fpr(W,"%07.7d",R->COD_MUN_ORI);
    Fpr(W,"%-14.14s",R->CNPJ_CPF_DEST.c_str());
    Fpr(W,"%-14.14s",R->IE_DEST.c_str());
    Fpr(W,"%07.7d",R->COD_MUN_DEST);
    Fpr(W,"%01.1d",R->IND_CARGA);
    Fpr(W,"%-14.14s",R->CNPJ_COL.c_str());
    Fpr(W,"%-14.14s",R->IE_COL.c_str());
    Fpr(W,"%07.7d",R->COD_MUN_COL);
    Fpr(W,"%-14.14s",R->CNPJ_ENTG.c_str());
    Fpr(W,"%-14.14s",R->IE_ENTG.c_str());
    Fpr(W,"%07.7d",R->COD_MUN_ENTG);
    Fpr(W,"%2.2s",R->COD_MOD.c_str());
    Fpr(W,"%5.5s",R->SER.c_str());
    Fpr(W,"%09.9d",StrToIntDef(R->NUM_DOC,0));
    Fpr(W,"%8.8s",DataStr(R->DT_DOC).c_str());
    Fpr(W,"%-12.12s",AjustaNumerico(R->VL_DOC,2));
    Fpr(W,"%-12.12s",AjustaNumerico(R->VL_MERC,2));
    Fpr(W,"%8.8d",R->QTD_VOL);
    Fpr(W,"%-10.10s",AjustaNumerico(R->PESO_BRT,2));
    Fpr(W,"%-10.10s",AjustaNumerico(R->PESO_LIQ,2));
    Fpr(W,"%25s"," ");    
    Fpr(W,"\n");
    Contador++;
    Limpa(R,true);
   }
  L_49->Clear();
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH_50(void)
{
  struct REGISTRO_50 *R;
  for(int i=0;i<L_50->Count;i++)
   {
    R = (struct REGISTRO_50 *)L_50->Items[i];
    Fpr(W,"50");
    Fpr(W,"%-70.70s",R->DESC_PADRAO.c_str());
    Fpr(W,"%-120.120s",R->DESC_COMPL.c_str());
    Fpr(W,"%64s"," ");
    Fpr(W,"\n");
    Contador++;
    Limpa(R);
   }
  L_50->Clear();
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH_51(void)
{
  struct REGISTRO_51 *R;
  for(int i=0;i<L_51->Count;i++)
   {
    R = (struct REGISTRO_51 *)L_51->Items[i];
    Fpr(W,"51");
    Fpr(W,"%-30.30s",R->NUM_PROC.c_str());
    Fpr(W,"%01.1d",R->IND_PROC);
    Fpr(W,"%223s"," ");
    Fpr(W,"\n");
    Contador++;
    Limpa(R);
   }
  L_51->Clear();
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH_52(void)
{
  struct REGISTRO_52 *R;
  for(int i=0;i<L_52->Count;i++)
   {
    R = (struct REGISTRO_52 *)L_52->Items[i];
    Fpr(W,"52");
    Fpr(W,"%01.1d",R->COD_DA);
    Fpr(W,"%2.2s",R->UF.c_str());
    Fpr(W,"%-12.12s",R->NUM_DA.c_str());
    Fpr(W,"%-43.43s",R->COD_AUT.c_str());
    Fpr(W,"%-12.12s",AjustaNumerico(R->VL_DA,2));
    Fpr(W,"%8.8s",DataStr(R->DT_VCTO).c_str());
    Fpr(W,"%8.8s",DataStr(R->DT_PGTO).c_str());
    Fpr(W,"%168s"," ");
    Fpr(W,"\n");
    Contador++;
    Limpa(R);
   }
  L_52->Clear();
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH_53(void)
{
  struct REGISTRO_53 *R;
  for(int i=0;i<L_53->Count;i++)
   {
    R = (struct REGISTRO_53 *)L_53->Items[i];
    Fpr(W,"53");
    Fpr(W,"%01.1d",R->IND_OPER);
    Fpr(W,"%01.1d",R->IND_EMIT);
    Fpr(W,"%-14.14s",R->COD_PART.c_str());
    Fpr(W,"%2.2s",R->COD_MOD.c_str());
    Fpr(W,"%5.5s",R->SER.c_str());
    Fpr(W,"%5.5s",R->SUB.c_str());
    Fpr(W,"%09.9d",R->NUM_DOC);
    Fpr(W,"%8.8s",DataStr(R->DT_DOC).c_str());
    Fpr(W,"%209s"," ");
    Fpr(W,"\n");
    Contador++;
    Limpa(R);
   }
  L_53->Clear();
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH_54(void)
{
  struct REGISTRO_54 *R;
  for(int i=0;i<L_54->Count;i++)
   {
    R = (struct REGISTRO_54 *)L_54->Items[i];
    Fpr(W,"54");
    Fpr(W,"%2.2s",R->COD_MOD.c_str());
    Fpr(W,"%-25.25s",R->ECF_FAB.c_str());
    Fpr(W,"%03.3d",R->ECF_CX);
    Fpr(W,"%09.9d",R->NUM_DOC);
    Fpr(W,"%8.8s",DataStr(R->DT_DOC).c_str());
    Fpr(W,"%207s"," ");
    Fpr(W,"\n");
    Contador++;
    Limpa(R);
   }
  L_54->Clear();
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH_55(void)
{
  struct REGISTRO_55 *R;
  for(int i=0;i<L_55->Count;i++)
   {
    R = (struct REGISTRO_55 *)L_55->Items[i];
    Fpr(W,"55");
    Fpr(W,"%01.1d",R->IND_CARGA);
    Fpr(W,"%14.14s",R->CNPJ_COL.c_str());
    Fpr(W,"%-14.14s",R->IE_COL.c_str());
    Fpr(W,"%11.11s",R->CPF_COL.c_str());
    Fpr(W,"%07.7d",R->COD_MUN_COL);
    Fpr(W,"%14.14s",R->CNPJ_ENTG.c_str());
    Fpr(W,"%-14.14s",R->IE_ENTG.c_str());
    Fpr(W,"%11.11s",R->CPF_ENTG.c_str());
    Fpr(W,"%7.7d",R->COD_MUN_ENTG);
    Fpr(W,"%161s"," ");
    Fpr(W,"\n");
    Contador++;
    Limpa(R);
   }
  L_55->Clear();
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH_58(void)
{
  struct REGISTRO_58 *R;
  for(int i=0;i<L_58->Count;i++)
   {
    R = (struct REGISTRO_58 *)L_58->Items[i];
    Fpr(W,"58");
    Fpr(W,"%01.1d",R->COD_DOC_IMP);
    Fpr(W,"%-30.30s",R->NUM_DOC_IMP.c_str());
    Fpr(W,"%-12.12s",AjustaNumerico(R->PIS_IMP,2));
    Fpr(W,"%-12.12s",AjustaNumerico(R->COFINS_IMP,2));
    Fpr(W,"%-11.11s",R->NUM_DRAWBACK.c_str());
    Fpr(W,"%188s"," ");
    Fpr(W,"\n");
    Contador++;
    Limpa(R);
   }
  L_58->Clear();
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH_59(void)
{
  struct REGISTRO_59 *R;
  for(int i=0;i<L_59->Count;i++)
   {
    R = (struct REGISTRO_59 *)L_59->Items[i];
    Fpr(W,"59");
    Fpr(W,"%-14.14s",R->COD_PART.c_str());
    Fpr(W,"%8.8s",R->VEIC_ID.c_str());
    Fpr(W,"%-30.30s",R->COD_AUT.c_str());
    Fpr(W,"%-30.30s",R->NR_PASSE.c_str());
    Fpr(W,"%06.6d",R->HORA);
    Fpr(W,"%-4.4s",AjustaNumerico(R->TEMPER,2));
    Fpr(W,"%4.4d",R->QTD_VOL);
    Fpr(W,"%-12.12s",AjustaNumerico(R->PESO_BRT,2));
    Fpr(W,"%-12.12s",AjustaNumerico(R->PESO_LIQ,2));
    Fpr(W,"%-45.45s",R->NOM_MOT.c_str());
    Fpr(W,"%11.11s",R->CPF.c_str());
    Fpr(W,"%2.2s",R->UF_ID.c_str());
    Fpr(W,"%76s"," ");
    Fpr(W,"\n");
    Contador++;
    Limpa(R);
   }
  L_59->Clear();
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH_60(void)
{
  struct REGISTRO_60 *R;
  for(int i=0;i<L_60->Count;i++)
   {
    R = (struct REGISTRO_60 *)L_60->Items[i];
    Fpr(W,"60");
    Fpr(W,"%2.2s",R->MOD_DOC.c_str());
    if(R->NUM_DOC > 0.00)
     {
      Fpr(W,"%02.2d",R->SIT_DOC);
      Fpr(W,"%09.9d",R->NUM_DOC);
     }
    else
     Fpr(W,"%11s"," ");
    Fpr(W,"%8.8s",DataStr(R->DT_EMISSAO).c_str());
    if(R->VL_TOTAL > 0.00)
     Fpr(W,"%-12.12s",AjustaNumerico(R->VL_TOTAL,2));
    else
     Fpr(W,"%12s"," ");
    Fpr(W,"%-14.14s",R->INSCRICAO.c_str());
    Fpr(W,"%-70.70s",R->NOME.c_str());
    Fpr(W,"%137s"," ");
    Fpr(W,"\n");
    Contador++;
    for(int j=0;j<R->CL_61->Count;j++)
     {
      R_61 = (struct REGISTRO_61 *)R->CL_61->Items[j];
      GrvPH(R_61);
      Limpa(R_61);
      if(R->CL_62->Count > j)
       {
        R_62 = (struct REGISTRO_62 *)R->CL_62->Items[j];
        GrvPH(R_62);
        Limpa(R_62);
       }
      if(R->CL_63->Count > j)
       {
        R_63 = (struct REGISTRO_63 *)R->CL_63->Items[j];
        GrvPH(R_63);
        Limpa(R_63);
       }
     }
    R->CL_61->Clear();
    R->CL_62->Clear();
    R->CL_63->Clear();
    Limpa(R);
   }
  L_60->Clear();
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH(struct REGISTRO_61 *R)
{
  Fpr(W,"61");
  Fpr(W,"%-14.14s",R->COD_PROPRIO.c_str());
  Fpr(W,"%-14.14s",R->COD_ANT_ITEM.c_str());
  while(R->NCM.Length() < 11)
   R->NCM = R->NCM + "0";
  Fpr(W,"%-11.11s",R->NCM.c_str());
  Fpr(W,"%-50.50s",R->DESCRICAO.c_str());
  Fpr(W,"%-30.30s",R->DESC_COMPLE.c_str());
  Fpr(W,"%-10.10s",R->UN_MED_DOC.c_str());
  Fpr(W,"%-20.20s",R->DESC_UN_DOC.c_str());
  Fpr(W,"%-10.10s",R->UN_MED_EST.c_str());
  Fpr(W,"%-20.20s",R->DESC_UN_EST.c_str());
  Fpr(W,"%-15.15s",AjustaNumerico(R->FAT_CONVERSAO,6));
  Fpr(W,"%1.1s",R->PROD_SERV.c_str());
  Fpr(W,"%-9.9s",R->COD_PROD_ANP.c_str());
  Fpr(W,"%-14.14s",R->COD_BARRAS.c_str());
  Fpr(W,"%02.2d",R->TIPO_ITEM);
  Fpr(W,"%2.2d",R->COD_GENERO_ITEM);
  Fpr(W,"%4.4d",R->COD_SERVICO);
  Fpr(W,"%-4.4s",AjustaNumerico(R->ALIQ_INT_ICMS,2));
  Fpr(W,"%24s"," ");
  Fpr(W,"\n");
  Contador++;
  Limpa(R);
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH(struct REGISTRO_62 *R)
{
  Fpr(W,"62");
  Fpr(W,"%-13.13s",AjustaNumerico(R->QTD,5));
  if(R->QTD_CANC > 0)
   Fpr(W,"%-13.13s",AjustaNumerico(R->QTD_CANC,5));
  else
   Fpr(W,"%13s"," ");
  Fpr(W,"%-12.12s",AjustaNumerico(R->VL_ITEM,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->VL_DESC,2));
  Fpr(W,"%1.1s",R->IND_MOV.c_str());
  Fpr(W,"%03.3d",R->CST_ICMS);
  Fpr(W,"%04.4d",R->CFOP);
  Fpr(W,"%-25.25s",R->COD_NAT.c_str());
  Fpr(W,"%-12.12s",AjustaNumerico(R->VL_BC_ICMS,2));
  Fpr(W,"%-4.4s",AjustaNumerico(R->ALIQ_ICMS,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->VL_ICMS,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->VL_BC_ICMS_ST,2));
  Fpr(W,"%-4.4s",AjustaNumerico(R->ALIQ_ST,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->VL_ICMS_ST,2));
  Fpr(W,"%01.1d",R->IND_APUR);
  if(R->VL_BC_IPI == 0.00 && R->CST_IPI == 0)
   Fpr(W,"%70s"," ");
  else
   {
    Fpr(W,"%02.2d",R->CST_IPI);
    Fpr(W,"%03.3d",R->ENQUAD_IPI);
    Fpr(W,"%-12.12s",AjustaNumerico(R->VL_BC_IPI,2));
    Fpr(W,"%-5.5s",AjustaNumerico(R->ALIQ_IPI,2));
    Fpr(W,"%-6.6s",R->COD_SELO_IPI.c_str());
    Fpr(W,"%9.9d",R->QT_SELO_IPI);
    Fpr(W,"%5.5d",R->CL_ENQ);
    Fpr(W,"%-8.8s",AjustaNumerico(R->VL_UNID,2));
    Fpr(W,"%-8.8s",AjustaNumerico(R->QUANT_PAD,3));
    Fpr(W,"%-12.12s",AjustaNumerico(R->VL_IPI,2));
   }
  Fpr(W,"%04.4d",R->ENQUAD_PIS);
  Fpr(W,"%04.4d",R->ENQUAD_COFINS);
  Fpr(W,"%07.7d",R->COD_CTA);
  if(R->COD_CLASSIF > 0)
   Fpr(W,"%4.4d",R->COD_CLASSIF);
  else
   Fpr(W,"%4s"," ");
  if(R->TIPO_RECEITA > 0)
   Fpr(W,"%1.1d",R->TIPO_RECEITA);
  else
   Fpr(W,"%1S"," ");
  Fpr(W,"%14.14s",R->CNPJ.c_str());
  if(R->VL_NT > 0.0099)
   Fpr(W,"%-10.10s",AjustaNumerico(R->VL_NT,2));
  else
   Fpr(W,"%10s"," ");
  Fpr(W,"\n");
  Contador++;
  for(int i=0;i<R->CL_65->Count;i++)
   {
    R_65 = (struct REGISTRO_65 *)R->CL_65->Items[i];
    GrvPH(R_65);
   }
  for(int i=0;i<R->CL_66->Count;i++)
   {
    R_66 = (struct REGISTRO_66 *)R->CL_66->Items[i];
    GrvPH(R_66);
   }
  for(int i=0;i<R->CL_67->Count;i++)
   {
    R_67 = (struct REGISTRO_67 *)R->CL_67->Items[i];
    GrvPH(R_67);
   }
  for(int i=0;i<R->CL_68->Count;i++)
   {
    R_68 = (struct REGISTRO_68 *)R->CL_68->Items[i];
    GrvPH(R_68);
   }
  R->CL_65->Clear();
  R->CL_66->Clear();
  R->CL_67->Clear();
  R->CL_68->Clear();
  Limpa(R);
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH(struct REGISTRO_63 *R)
{
  Fpr(W,"63");
  Fpr(W,"%-12.12s",AjustaNumerico(R->BC_ST_ORIG_DEST,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->ICMS_ST_REP,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->ICMS_ST_COMPL,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->BC_RET,2));
  Fpr(W,"%-12.12s",AjustaNumerico(R->ICMS_RET,2));
  Fpr(W,"%2.2d",R->COD_MOD_ULT_E);
  Fpr(W,"%09.9d",R->NUM_DOC_ULT_E);
  Fpr(W,"%5.5s",R->SER_ULT_E.c_str());
  Fpr(W,"%8.8s",DataStr(R->DT_ULT_E).c_str());
  Fpr(W,"%14.14s",R->COD_PART_ULT_E.c_str());
  Fpr(W,"%-12.12s",AjustaNumerico(R->QUANT_ULT_E,3));
  Fpr(W,"%-12.12s",AjustaNumerico(R->VL_UNIT_ULT_E,3));
  Fpr(W,"%-12.12s",AjustaNumerico(R->VL_UNIT_BC_ST,3));
  Fpr(W,"%120s"," ");
  Fpr(W,"\n");
  Contador++;
  for(int i=0;i<R->CL_65->Count;i++)
   {
    R_65 = (struct REGISTRO_65 *)R->CL_65->Items[i];
    GrvPH(R_65);
   }
  for(int i=0;i<R->CL_66->Count;i++)
   {
    R_66 = (struct REGISTRO_66 *)R->CL_66->Items[i];
    GrvPH(R_66);
   }
  for(int i=0;i<R->CL_67->Count;i++)
   {
    R_67 = (struct REGISTRO_67 *)R->CL_67->Items[i];
    GrvPH(R_67);
   }
  for(int i=0;i<R->CL_68->Count;i++)
   {
    R_68 = (struct REGISTRO_68 *)R->CL_68->Items[i];
    GrvPH(R_68);
   }
  R->CL_65->Clear();
  R->CL_66->Clear();
  R->CL_67->Clear();
  R->CL_68->Clear();
  Limpa(R);
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH(struct REGISTRO_65 *R)
{
  Fpr(W,"65");
  Fpr(W,"%-20.20s",R->NUM_TANQUE);
  Fpr(W,"%-10.10s",AjustaNumerico(R->QTDE,3));
  Fpr(W,"%224s"," ");
  Fpr(W,"\n");
  Contador++;
  Limpa(R);
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH(struct REGISTRO_66 *R)
{
  Fpr(W,"66");
  Fpr(W,"%-25.25s",R->LOTE_MED.c_str());
  Fpr(W,"%-10.10s",AjustaNumerico(R->QTD_ITEM,0));
  Fpr(W,"%8.8s",DataStr(R->DT_FAB).c_str());
  Fpr(W,"%8.8s",DataStr(R->DT_VAL).c_str());
  Fpr(W,"%01.1d",R->IND_MED);
  Fpr(W,"%01.1d",R->TP_PROD);
  Fpr(W,"%-12.12s",AjustaNumerico(R->VL_TAB_MAX,2));
  Fpr(W,"%189s"," ");
  Fpr(W,"\n");
  Contador++;
  Limpa(R);
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH(struct REGISTRO_67 *R)
{
  Fpr(W,"67");
  Fpr(W,"%01.1d",R->IND_ARM);
  Fpr(W,"%-25.25s",R->NUM_ARM.c_str());
  Fpr(W,"%-150.150s",R->DESCR_COMPL.c_str());
  Fpr(W,"%78s"," ");
  Fpr(W,"\n");
  Contador++;
  Limpa(R);
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH(struct REGISTRO_68 *R)
{
  Fpr(W,"68");
  Fpr(W,"%01.1d",R->IND_VEIC_OPER);
  Fpr(W,"%14.14s",R->CNPJ.c_str());
  Fpr(W,"%2.2s",R->UF.c_str());
  Fpr(W,"%-30.30s",R->CHASSI_VEIC.c_str());
  Fpr(W,"%207s"," ");
  Fpr(W,"\n");
  Contador++;
  Limpa(R);
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH_75(void)
{
  struct REGISTRO_75 *R;
  for(int i=0;i<L_75->Count;i++)
   {
    R = (struct REGISTRO_75 *)L_75->Items[i];
    Fpr(W,"75");
    Fpr(W,"%-14.14s",R->COD_PROPRIO.c_str());
    Fpr(W,"%-14.14s",R->COD_ANT_ITEM.c_str());
    while(R->NCM.Length() < 11)
     R->NCM = R->NCM + "0";
    Fpr(W,"%-11.11s",R->NCM.c_str());
    Fpr(W,"%-50.50s",R->DESCRICAO.c_str());
    Fpr(W,"%-30.30s",R->DESC_COMPLE.c_str());
    Fpr(W,"%-10.10s",R->UN_MED_DOC.c_str());
    Fpr(W,"%-20.20s",R->DESC_UN_DOC.c_str());
    Fpr(W,"%-10.10s",R->UN_MED_EST.c_str());
    Fpr(W,"%-20.20s",R->DESC_UN_EST.c_str());
    Fpr(W,"%-15.15s",AjustaNumerico(R->FAT_CONVERSAO,6));
    Fpr(W,"%1.1s",R->PROD_SERV.c_str());
    Fpr(W,"%-9.9s",R->COD_PROD_ANP.c_str());
    Fpr(W,"%-14.14s",R->COD_BARRAS.c_str());
    Fpr(W,"%02.2d",R->TIPO_ITEM);
    Fpr(W,"%2.2d",R->COD_GENERO_ITEM);
    Fpr(W,"%4.4d",R->COD_SERVICO);
    Fpr(W,"%-4.4s",AjustaNumerico(R->ALIQ_INT_ICMS,2));
    Fpr(W,"%24s"," ");
    Fpr(W,"\n");
    Contador++;

    GrvPH_76(R->R_76);

    Limpa(R);
   }
  L_75->Clear();
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH_76(struct REGISTRO_76 *R)
{
  Fpr(W,"76");
  Fpr(W,"%8.8s",DataStr(R->DT_INV).c_str());
  Fpr(W,"%-12.12s",AjustaNumerico(R->QTD,3));
  Fpr(W,"%-15.15s",AjustaNumerico(R->VL_UNIT,6));
  Fpr(W,"%-15.15s",AjustaNumerico(R->VL_ITEM,2));
  Fpr(W,"%01.1d",R->IND_PROP);
  Fpr(W,"%-50.50s",R->TXT_COMPL.c_str());
  Fpr(W,"%-15.15s",R->COD_CTA.c_str());
  Fpr(W,"%138s"," ");
  Fpr(W,"\n");
  Contador++;

  if(R->R_77->GRAVAR)
   GrvPH_77(R->R_77);

  Limpa(R);
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH_77(struct REGISTRO_77 *R)
{
  Fpr(W,"77");
  Fpr(W,"%-40.40s",R->NOME.c_str());
  Fpr(W,"%-18.18s",R->INSCRICAO.c_str());
  Fpr(W,"%01.1d",R->TIPO_INSC);
  Fpr(W,"%-14.14s",R->IE.c_str());
  Fpr(W,"%-40.40s",R->ENDERECO.c_str());
  Fpr(W,"%-14.14s",R->BAIRRO.c_str());
  Fpr(W,"%-9.9s",R->CEP.c_str());
  Fpr(W,"%-2.2s",R->ESTADO.c_str());
  Fpr(W,"%-25.25s",R->MUNICIPIO.c_str());
  Fpr(W,"%08.8d",R->CCD_CONTABIL);
  Fpr(W,"%12.12s",R->CEI_NIT.c_str());
  Fpr(W,"%14.14s",R->IM.c_str());
  Fpr(W,"%11.11s",R->TELEFONE.c_str());
  Fpr(W,"%-40.40s",R->NOME_FANT.c_str());
  Fpr(W,"%6s"," ");
  Fpr(W,"\n");
  Contador++;
  Limpa(R);
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH_80(void)
{
  struct REGISTRO_80 *R;
  for(int i=0;i<L_80->Count;i++)
   {
    R = (struct REGISTRO_80 *)L_80->Items[i];
    Fpr(W,"80");
    Fpr(W,"%-14.14s",R->COD_ITEM.c_str());
    Fpr(W,"%8.8s",DataStr(R->DT_FECH).c_str());
    Fpr(W,"%-12.12s",AjustaNumerico(R->ESTQ_ABERT,3));
    Fpr(W,"%-12.12s",AjustaNumerico(R->VOL_ENTR,3));
    Fpr(W,"%-12.12s",AjustaNumerico(R->VOL_DISP,3));
    Fpr(W,"%-12.12s",AjustaNumerico(R->VOL_SAIDAS,3));
    Fpr(W,"%-12.12s",AjustaNumerico(R->ESTQ_ESCR,3));
    Fpr(W,"%-12.12s",AjustaNumerico(R->VL_AJ_PERDA,3));
    Fpr(W,"%-12.12s",AjustaNumerico(R->VL_AJ_GANHO,3));
    Fpr(W,"%-12.12s",AjustaNumerico(R->FECH_FISICO,3));
    Fpr(W,"%136s"," ");
    Fpr(W,"\n");
    Contador++;
    for(int i=0;i<R->CL_81->Count;i++)
    {
     R_81 = (struct REGISTRO_81 *)R->CL_81->Items[i];
     GrvPH_81(R_81);
    }
    R->CL_81->Clear();
    Limpa(R);
   }
  L_80->Clear();
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH_81(struct REGISTRO_81 *R)
{
  Fpr(W,"81");
  Fpr(W,"%-10d",R->NUM_TANQUE);
  Fpr(W,"%-12.12s",AjustaNumerico(R->ESTQ_ABERT,3));
  Fpr(W,"%-12.12s",AjustaNumerico(R->VOL_ENTR,3));
  Fpr(W,"%-12.12s",AjustaNumerico(R->VOL_DISP,3));
  Fpr(W,"%-12.12s",AjustaNumerico(R->VOL_SAIDAS,3));
  Fpr(W,"%-12.12s",AjustaNumerico(R->ESTQ_ESCR,3));
  Fpr(W,"%-12.12s",AjustaNumerico(R->VL_AJ_PERDA,3));
  Fpr(W,"%-12.12s",AjustaNumerico(R->VL_AJ_GANHO,3));
  Fpr(W,"%-12.12s",AjustaNumerico(R->FECH_FISICO,3));
  Fpr(W,"%148s"," ");
  Fpr(W,"\n");
  Contador++;
  for(int i=0;i<R->CL_82->Count;i++)
  {
   R_82 = (struct REGISTRO_82 *)R->CL_82->Items[i];
   GrvPH_82(R_82);
  }
  R->CL_82->Clear();
  Limpa(R);
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH_82(struct REGISTRO_82 *R)
{
  Fpr(W,"82");
  Fpr(W,"%10.10d",R->NUM_BICO);
  Fpr(W,"%-30.30s",R->NR_INTERV.c_str());
  Fpr(W,"%-50.50s",R->MOT_INTERV.c_str());
  Fpr(W,"%-30.30s",R->NOM_INTERV.c_str());
  Fpr(W,"%14.14s",R->CNPJ_INTERV.c_str());
  Fpr(W,"%11.11s",R->CPF_INTERV.c_str());
  Fpr(W,"%-12.12s",AjustaNumerico(R->VAL_FECHA,3));
  Fpr(W,"%-12.12s",AjustaNumerico(R->VAL_ABERT,3));
  Fpr(W,"%-12.12s",AjustaNumerico(R->VOL_AFERI,3));
  Fpr(W,"%-12.12s",AjustaNumerico(R->VOL_VENDAS,3));
  Fpr(W,"%61.61s"," ");
  Fpr(W,"\n");
  Contador++;
  Limpa(R);
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH_83(void)
{
  struct REGISTRO_83 *R;
  for(int i=0;i<L_83->Count;i++)
   {
    R = (struct REGISTRO_83 *)L_83->Items[i];
    Fpr(W,"83");
    Fpr(W,"%-30.30s",R->SERIE.c_str());
    Fpr(W,"%-60.60s",R->FABRICANTE.c_str());
    Fpr(W,"%-50.50s",R->MODELO.c_str());
    Fpr(W,"%01.1d",R->TIPO_MEDICAO);
    Fpr(W,"%113s"," ");
    Fpr(W,"\n");
    Contador++;
    for(int i=0;i<R->CL_84->Count;i++)
    {
     R_84 = (struct REGISTRO_84 *)R->CL_84->Items[i];
     GrvPH_84(R_84);
    }
    R->CL_84->Clear();
    for(int i=0;i<R->CL_85->Count;i++)
    {
     R_85 = (struct REGISTRO_85 *)R->CL_85->Items[i];
     GrvPH_85(R_85);
    }
    R->CL_85->Clear();
    Limpa(R);
   }
  L_83->Clear();
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH_84(struct REGISTRO_84 *R)
{
  Fpr(W,"84");
  Fpr(W,"%-30.30s",R->NUM_LACRE.c_str());
  Fpr(W,"%8.8s",DataStr(R->DT_APLICACAO).c_str());
  Fpr(W,"%216s"," ");
  Fpr(W,"\n");
  Contador++;
  Limpa(R);
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::GrvPH_85(struct REGISTRO_85 *R)
{
  Fpr(W,"85");
  Fpr(W,"%10.10d",R->NUM_BICO);
  Fpr(W,"%-14.14s",R->COD_ITEM.c_str());
  Fpr(W,"%10.10d",R->NUM_TANQUE);
  Fpr(W,"%220s"," ");
  Fpr(W,"\n");
  Contador++;
  Limpa(R);
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_10 *R)
{
  R->GRAVAR = false;
  R->CNPJ = "";
  R->IE = "";
  R->MES_ANO = 0;
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_20S *R)
{
  R->GRAVAR = false;
  R->DIA = 0;
  R->ESPECIE = "";
  R->SERIE = "";
  R->DOCUMENTO = 0;
  R->SEQUENCIA = 0;
  R->ESTADO = "";
  R->CFOP = 0;
  R->HISTORICO = 0;
  R->MUN_ORIGEM = "";
  R->OBS = "";
  R->MOD_DOCUMENTO = "";
  R->MOD_FRETE = 0;
  R->SAIDA_EXP = 0;
  R->SITUACAO_DOC = 0;
  R->SUB_CODIGO = 0;
  R->AGRUPAR_LCTO = 0;
  R->DOC_ELETRONICO = "";
  R->CHAVE = "";
  R->DT_SAIDA = 0;
  R->COMPLEMENTO = "";
  R->DOC_CANCELADOS = "";
  R->TIPO_FATURA = 0;
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_20E *R)
{
  R->GRAVAR = false;
  R->DIA = 0;
  R->DT_DOCUMENTO = 0;
  R->ESPECIE = "";
  R->SERIE = "";
  R->DOCUMENTO = 0;
  R->CFOP = 0;
  R->HISTORICO = 0;
  R->OBS = "";
  R->MOD_DOCUMENTO = "";
  R->MOD_FRETE = 0;
  R->SITUACAO_DOC = 0;
  R->SUB_CODIGO = 0;
  R->INDICADOR = "";
  R->EXEC_FORA = "";
  R->EXEC_TERCEIROS = "";
  R->COD_ATIVIDADE = "";
  R->TIPO_NF = 0;
  R->DOC_ELETRONICO = "";
  R->CHAVE = "";
  R->COMPLEMENTO = "";
  R->TIPO_FATURA = 0;
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_21S *R)
{
  R->GRAVAR = false;
  R->VALOR = 0.00;
  R->FRETE = 0.00;
  R->SEGURO = 0.00;
  R->OUTRAS = 0.00;
  R->DESCONTO = 0.00;
  for(int i=0;i<5;i++)
   {
    R->BASE_IRPJ[i] = 0.00;
    R->ALIQUOTA[i] = 0.00;
    R->VL_CONTABIL[i] = 0.00;
   }
  R->DEDUCAO = 0.00;
  R->PIS_COFINS = 0.00;
  R->APROP_CRED = 0.00;
  R->RESSARC_ST = 0.00;
  R->TRANSF_CREDITO = 0.00;
  R->VL_COMPLE = 0.00;
  R->SERVICO_NT = 0.00;
  R->CC_DEBITO = 0;
  R->CC_CREDITO = 0;
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_21E *R)
{
  R->GRAVAR = false;
  R->VALOR = 0.00;
  R->FRETE = 0.00;
  R->SEGURO = 0.00;
  R->OUTRAS = 0.00;
  R->DESCONTO = 0.00;
  R->FUNRURAL = 0.00;
  R->BC_ICMS_SR = 0.00;
  R->ICMS_SR = 0;
  R->COD_ICMSST = 0.00;
  R->TIPO_ICMSSR = "";
  for(int i=0;i<5;i++)
   R->VL_CONTABIL[i] = 0.00;
  R->PIS_COFINS = 0.00;
  R->APROP_CRED = 0.00;
  R->RESSARC_ST = 0.00;
  R->TRANSF_CREDITO = 0.00;
  R->VALOR_COMPLE = 0.00;
  R->SERVICO_NT = 0.00;
  R->CC_DEBITO = 0;
  R->CC_CREDITO = 0;
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_22 *R)
{
  R->GRAVAR = false;
  R->NOME = "";
  R->INSCRICAO = "";
  R->TIPO_INSC = 0;
  R->IE = "";
  R->ENDERECO = "";
  R->BAIRRO = "";
  R->CEP = "";
  R->ESTADO = "";
  R->MUNICIPIO = "";
  R->CCD_CONTABIL = 0;
  R->CEI_NIT = "";
  R->IM = "";
  R->TELEFONE = "";
  R->NOME_FANT = "";
  R->PAIS = "";
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_23S *R)
{
  R->GRAVAR = false;
  for(int i=0;i<5;i++)
   {
    R->BASE_CALCULO[i] = 0.00;
    R->ALIQUOTA[i] = 0.00;
    R->VALOR_ICMS[i] = 0.00;
   }
  R->ISENTAS = 0;
  R->OUTRAS = 0;
}

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_23E *R)
{
  R->GRAVAR = false;
  for(int i=0;i<5;i++)
   {
    R->BASE_CALCULO[i] = 0.00;
    R->ALIQUOTA[i] = 0.00;
    R->VALOR_ICMS[i] = 0.00;
   }
  R->ISENTAS = 0;
  R->OUTRAS = 0;
  R->BC_DIF_ALIQ_ICMS = 0.00;
  R->ALIQ_DIF_ICMS = 0.00;
  R->VL_DIF_ALIQ_ICMS = 0.00;
  R->TIP_DIF_ALIQ_ICMS = 0;
  R->TIP_LCTO = 0;
  R->APURACAO = 0;
  R->BC_ICMS_DCIP = 0.00;
  R->ALIQ_ICMS_DCIP = 0.00;
}

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_24 *R)
{
  R->GRAVAR = false;
  R->NUM_EQUIP = 0;
  R->NUM_SERIE = "";
  R->NUM_REDUCAOZ = 0;
  R->INICIO_DIA = 0.00;
  R->CRO = 0;
  R->FINAL_DIA = 0.00;
  R->OPERACOES_ST = 0.00;
  R->ISENTAS = 0.00;
  R->NAO_INCIDENCIA = 0.00;
  R->CANCELAMENTOS = 0.00;
  R->DESCONTOS = 0.00;
  R->ISSQN = 0.00;
  R->NUM_INICIAL = 0;
  R->NUM_FINAL = 0;
  R->VL_VISTA = 0.00;
  R->MOD_EQUIPAMENTO = "";
  R->ACRESCIMOS = 0.00;
  R->CANC_ISS = 0.00;
  R->DESC_ISS = 0.00;
  R->ACRES_ISS = 0.00;
  R->OPER_NAOFISCAIS = 0.00;
  R->CANC_NAOFISCAIS = 0.00;
  R->DESC_NAOFISCAIS = 0.00;
  R->ACRES_NAOFISCAIS = 0.00;
  R->IOF = 0.00;
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_25 *R)
{
  R->GRAVAR = false;
  R->BASE_CALCULO = 0.00;
  R->ALIQUOTA = 0.00;
  R->IPI = 0.00;
  R->ISENTAS = 0.00;
  R->OUTRAS = 0.00;
  R->TOTALIPI = 0.00;
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_26 *R)
{
  R->GRAVAR = false;
  R->BASE_CALCULO = 0.00;
  R->ALIQUOTA = 0.00;
  R->ISS = 0.00;
  R->IMPOSTO_RETIDO = 0.00;
  R->ISENTAS_OUTRAS = 0.00;
  R->SUBST_TRIB = 0.00;
  R->MAT_APLICADOS = 0.00;
  R->SUB_EMPREITADAS = 0.00;
  R->OBS = "";
  R->EXEC_FORAMUN = "";
  R->EXEC_BTERC = "";
  R->RETENCAO = "";
  R->COD_MUN = 0;
  R->SITUACAO_NF = 0;
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_27 *R)
{
  R->GRAVAR = false;
  R->BASE_CALCULO = 0.00;
  R->ALIQUOTA = 0.00;
  R->VALOR = 0.00;
  R->TIPO_LTCO = 0;
  R->APURACAO = 0;
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_28 *R)
{
  R->CODIGO = 0;
  R->VALOR = 0.00;
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_29 *R)
{
  R->CLASSIF_FISCAL = "";
  R->DESCRICAO = "";
  R->UNIDADE = "";
  R->PRODUTO = "";
  R->CODIGO = "";
  R->QUANTIDADE = 0.000;
  R->VL_TOTAL = 0.00;
  R->VL_DESC = 0.00;
  R->COD_SITUACAOTRIB = 0;
  R->BASE_ICMS = 0.00;
  R->REDUCAO_BICMS = 0.00;
  R->ALIQ_ICMSCALC = 0.00;
  R->ALiQ_ICMSINT = 0.00;
  R->BC_ICMS_ST = 0.00;
  R->VL_UNICMS_ST = 0.00;
  R->ALIQ_IPI = 0.00;
  R->VL_IPI = 0.00;
  R->IND_IPI = 0;
  R->VL_ICMS_ST = 0.00;
  R->MOV_FISICA = "";
  R->NUM_SERIE = "";
  R->TIPO_INFO = 0;
  R->CST_PREPOND = 0;
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_30 *R)
{
  R->GRAVAR = false;
  R->TRANSPORTADOR = "";
  R->INSCRICAO = "";
  R->TIPO_INSCR = 0;
  R->IE = "";
  R->ENDERECO = "";
  R->BAIRRO = "";
  R->CEP = "";
  R->ESTADO = "";
  R->MUNICIPIO = "";
  R->VIA_TRANSPORTE = "";
  R->QTD_VOLUMES = 0;
  R->ESP_VOLUME = "";
  R->PESO_BRUTO = 0.00;
  R->PESO_LIQUIDO = 0.00;
  R->MOD_FRETE = 0;
  R->IDE_VEICULO = "";
  R->TIPO_FATURA = 0;
  R->IE_ST = "";
  R->OBS = "";
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_31 *R)
{
  R->GRAVAR = false;
  R->MEDIC_PERF_HIG = 0.00;
  R->COMBUST = 0.00;
  for(int i=0;i<3;i++)
   R->VEICULOS[i] = 0.00;
  R->CIGARROS = 0.00;
  R->ALIQ_BASE = 0.00;
  R->ALIQ_DEV = 0.00;
  R->ALIQ_AQUI = 0.00;
  R->ALIQ_OUTRAS = 0.00;
  R->VENDA_PARTES = 0.00;
  for(int i=0;i<2;i++)
   {
    R->TIPO_PRODUTO[i] = 0;
    R->PNEUS_CAM[i] = 0.00;
    R->DEVOL[i] = 0.00;
    R->OUTRAS_DED[i] = 0.00;
    R->VENDAS_RED[i] = 0.00;
   }
  R->VL_CONCESS = 0.00;
  R->BEBIDAS = 0.00;
  R->MP_EMBBEB = 0.00;
  R->ALDIF_VENDABEB = 0.00;
  R->ALDIF_DEVOLBEB = 0.00;
  R->ALDIF_REVBEB = 0.00;
  R->ALDIF_BEBEMB = 0.00;
  R->ALDIF_AQUISCRED = 0.00;
  R->ICMS_IPI = 0.00;
  R->OUTROS_PRODUTOS = 0.00;
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_32 *R)
{
  R->UF = "";
  R->INSCRICAO = "";
  R->IE = "";
  R->DT_NF = 0;
  R->MODELO = 0;
  R->SERIE = "";
  R->SUB_SERIE = "";
  R->NUMERO = 0;
  R->VALOR = 0.00;
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_33 *R)
{
  R->DESCRICAO = "";
  R->VALOR = 0.00;
  R->VL_DESC = 0.00;
  R->VL_MATERIAL = 0.00;
  R->BASE_ISS = 0.00;
  R->ALIQ_ISS = 0.00;
  R->VL_ISS = 0.00;
  R->BASE_RETINSS = 0.00;
  R->ALIQ_RETINSS = 0.00;
  R->VL_RETINSS = 0.00;
  R->COD_ATIVIDADE = "";
  R->CST = 0.00;
  R->COD_PROPRIO = "";  
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_34 *R)
{
  R->GRAVAR = false;
  for(int i=0;i<2;i++)
   {
    R->RECEITA_CSLL[i] = 0.00;
    R->ALIQ_CSLL[i] = 0.00;
   }
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_35 *R)
{
  R->GRAVAR = false;
  R->BC_IRF = 0.00;
  R->ALIQ_IRF = 0.00;
  R->VL_IRF = 0.00;
  R->BC_INSS = 0.00;
  R->ALIQ_INSS = 0.00;
  R->VL_INSS = 0.00;
  R->BC_ISS = 0.00;
  R->ALIQ_ISS = 0.00;
  R->VL_ISS = 0.00;
  R->BC_CSLL = 0.00;
  R->ALIQ_CSLL = 0.00;
  R->VL_CSLL = 0.00;
  R->BC_COFINS = 0.00;
  R->ALIQ_COFINS = 0.00;
  R->VL_COFINS = 0.00;
  R->BC_PIS = 0.00;
  R->ALIQ_PIS = 0.00;
  R->VL_PIS = 0.00;
  R->IRF_ENT = 0;
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_36S *R)
{
  R->GRAVAR = false;
  R->ESTORNO_CREDITOS = 0.00;
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_36E *R)
{
  R->GRAVAR = false;
  R->CRED_TOTAL = 0.00;
  R->CRED_PROP = 0.00;
  R->CRED_PRESTOTAL = 0.00;
  R->CRED_PRESPROP = 0.00;
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_37 *R)
{
  R->GRAVAR = false;
  R->MERCADORIAS = 0.00;
  R->MERC_IND = 0.00;
  R->LOC_BENS_MOVEIS = 0.00;
  R->TRANSP_INTER = 0.00;
  R->ESCR_CONTABEIS = 0.00;
  for(int i=0;i<3;i++)
   {
    R->SERVICOS[i] = 0.00;
    R->ST_REV_MERC[i] = 0.00;
    R->ST_MERC[i] = 0.00;
    R->ISS_ST[i] = 0.00;
    R->RESERVADO[i] = "";
   }
  R->RESERVADO[1] = "";
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_38 *R)
{
  R->IND_TIT = 0;
  R->DESC_TIT = "";
  R->NUM_TIT = "";
  R->DT_VCTO = 0;
  R->VL_PARC = 0.00;
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_41 *R)
{
  R->COD_MUN_ORIG = 0;
  R->VL_SERV = 0.00;
  R->QTDE_BILHETES = 0;
  R->VL_BC_ICMS = 0.00;
  R->VL_ICMS = 0.00;
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_42 *R)
{
  R->COD_MOD = "";
  R->SERIE = "";
  R->SUB_SERIE = "";
  R->NUM_DOC_INI = 0;
  R->NUM_DOC_FIN = 0;
  R->DT_DOC = 0;
  R->CST_ICMS = 0;
  R->CFOP = 0;
  R->ALIQ_ICMS = 0.00;
  R->ACUMULADO = 0.00;
  R->DESCONTOS = 0.00;
  R->PREST_SERV = 0.00;
  R->BC_ICMS = 0.00;
  R->VL_ICMS = 0.00;
  R->CANCEL = "";
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_44 *R)
{
  R->NOME = "";
  R->INSCRICAO = "";
  R->TIPO_INSC = 0;
  R->IE = "";
  R->ENDERECO = "";
  R->BAIRRO = "";
  R->CEP = "";
  R->ESTADO = "";
  R->MUNICIPIO = "";
  R->CCD_CONTABIL = 0;
  R->CEI_NIT = "";
  R->IM = "";
  R->TELEFONE = "";
  R->NOME_FANT = "";
  R->PAIS = "";
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_45 *R)
{
  R->GRAVAR = false;
  R->COD_CLASSE = 0;
  R->QTDE_DOC_CONSOL = 0;
  R->DOC_CANC = "";
  R->CONSUMO_TOTAL = "";
  R->DT_EMI_INI = 0;
  R->DT_EMI_FIN = 0;
  R->NOME_ARQ_MESTRE = "";
  R->CHAVE_ARQ_MESTRE = "";
  for(int i=0;i<5;i++)
   {
    R->UF_ICMS_ST[i] = "";
    R->BC_ICMS_ST[i] = 0.00;
    R->VL_ICMS_ST[i] = 0.00;
   }
  R->COD_TPLIGACAO = 0;
  R->COD_GRTENSAO = 0;
  R->COD_TPASSINANTE = 0;
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_46 *R)
{
  R->IND_SERV = 0;
  R->DT_INI_SERV = 0;
  R->DT_FIN_SERV = 0;
  R->PER_FISCAL = 0;
  R->COD_AREA = "";
  R->TERMINAL = "";
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_47 *R)
{
  R->GRAVAR = false;
  R->TIPO_CTE = 0;
  R->CHAVE_CTE = "";
  R->COD_MUN_DEST = "";
  R->RESERVADO[1] = "";
  R->RESERVADO[2] = "";
  R->PLACA = "";
  R->UF_PLACA = "";
  R->INSCR_CONSIG = "";
  R->INSCR_REDESP = "";
  R->IND_REDESP = 0;
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_47R *R)
{
  R->GRAVAR = false;
  R->SEC_CAT = 0.00;
  R->VL_DESPACHO = 0.00;
  R->VL_PEDAGIO = 0.00;
  R->VL_OUTROS = 0.00;
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_47AQ *R)
{
  R->GRAVAR = false;
  R->TIPO_VEICULO = 0;
  R->IDE_EMBARC = "";
  R->TIPO_NAVEG = 0;
  R->NUM_VIAGEM = 0;
  R->DESP_PORTUARIAS = 0.00;
  R->DESP_CARG_DESCARGA = 0.00;
  R->VL_OUTROS = 0.00;
  R->VL_ADIC_FRETE = 0.00;
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_47AE *R)
{
  R->GRAVAR = false;
  R->IDE_AERONAVE = "";
  R->NUM_VOO = 0;
  R->TIPO_TARIFA = 0;
  R->PESO_TAXADO = 0.00;
  R->TAXA_TERRESTRE = 0.00;
  R->TAXA_REDESPACHO = 0.00;
  R->VL_OUTROS = 0.00;
  R->TAXA_ADVALOREM = 0.00;
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_47M *R)
{
  R->GRAVAR = false;
  R->REG_OPERADOR = "";
  R->NAT_FRETE = 0;
  R->GER_RISCO = 0.00;
  R->PEDAGIO = 0.00;
  R->VL_OUTROS = 0.00;
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_48 *R)
{
  R->IND_EMIT = 0;
  R->CNPJ_CPF_EMIT = "";
  R->UF_EMIT = "";
  R->IE_EMIT = "";
  R->COD_MUN_ORIG = 0;
  R->IE_TOM = "";
  R->UF_TOM = "";
  R->IE_TOM = "";
  R->COD_MUN_DEST = 0;
  R->COD_MOD = "";
  R->SER = "";
  R->SUB = "";
  R->NUM_DOC = 0;
  R->DT_DOC = 0;
  R->VL_DOC = 0.00;
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_49 *R, bool Todas)
{
  if(Todas)
   {
    R->DESPACHO = "";
    R->CNPJ_CPF_REM = "";
    R->IE_REM = "";
    R->COD_MUN_ORI = 0;
    R->CNPJ_CPF_DEST = "";
    R->IE_DEST = "";
    R->COD_MUN_DEST = 0;
    R->IND_CARGA = 0;
    R->CNPJ_COL = "";
    R->IE_COL = "";
    R->COD_MUN_COL = 0;
    R->CNPJ_ENTG = "";
    R->IE_ENTG = "";
    R->COD_MUN_ENTG = 0;
   }
  R->COD_MOD = "";
  R->SER = "";
  R->NUM_DOC = "";
  R->DT_DOC = 0;
  R->VL_DOC = 0.00;
  R->VL_MERC = 0.00;
  R->QTD_VOL = 0;
  R->PESO_BRT = 0.00;
  R->PESO_LIQ = 0.00;
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_50 *R)
{
  R->DESC_PADRAO = "";
  R->DESC_COMPL = "";
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_51 *R)
{
  R->NUM_PROC = "";
  R->IND_PROC = 0;
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_52 *R)
{
  R->COD_DA = 0;
  R->UF = "";
  R->NUM_DA = "";
  R->COD_AUT = "";
  R->VL_DA = 0.00;
  R->DT_VCTO = 0;
  R->DT_PGTO = 0;
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_53 *R)
{
  R->IND_OPER = 0;
  R->IND_EMIT = 0;
  R->COD_PART = "";
  R->COD_MOD = "";
  R->SER = "";
  R->SUB = "";
  R->NUM_DOC = 0;
  R->DT_DOC = 0;
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_54 *R)
{
  R->COD_MOD = "";
  R->ECF_FAB = "";
  R->ECF_CX = 0;
  R->NUM_DOC = 0;
  R->DT_DOC = 0;
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_55 *R)
{
  R->IND_CARGA = 0;
  R->CNPJ_COL = "";
  R->IE_COL = "";
  R->CPF_COL = "";
  R->COD_MUN_COL = 0;
  R->CNPJ_ENTG = "";
  R->IE_ENTG = "";
  R->CPF_ENTG = "";
  R->COD_MUN_ENTG = 0;
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_58 *R)
{
  R->COD_DOC_IMP = 0;
  R->NUM_DOC_IMP = "";
  R->PIS_IMP = 0.00;
  R->COFINS_IMP = 0.00;
  R->NUM_DRAWBACK = "";
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_59 *R)
{
  R->COD_PART = "";
  R->VEIC_ID = "";
  R->COD_AUT = "";
  R->NR_PASSE = "";
  R->HORA = 0;
  R->TEMPER = 0.00;
  R->QTD_VOL = 0;
  R->PESO_BRT = 0.00;
  R->PESO_LIQ = 0.00;
  R->NOM_MOT = "";
  R->CPF = "";
  R->UF_ID = "";
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_60 *R)
{
  R->MOD_DOC = "";
  R->SIT_DOC = 0;
  R->NUM_DOC = 0;
  R->DT_EMISSAO = 0;
  R->VL_TOTAL = 0.00;
  R->INSCRICAO = "";
  R->NOME = "";
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_61 *R)
{
  R->COD_PROPRIO = "";
  R->COD_ANT_ITEM = "";
  R->NCM = "";
  R->DESCRICAO = "";
  R->DESC_COMPLE = "";
  R->UN_MED_DOC = "";
  R->DESC_UN_DOC = "";
  R->UN_MED_EST = "";
  R->DESC_UN_EST = "";
  R->FAT_CONVERSAO = 0.00;
  R->PROD_SERV = "";
  R->COD_PROD_ANP = "";
  R->COD_BARRAS = "";
  R->TIPO_ITEM = 0;
  R->COD_GENERO_ITEM = 0;
  R->COD_SERVICO = 0;
  R->ALIQ_INT_ICMS = 0.00;
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_62 *R)
{
  R->QTD = 0.00;
  R->QTD_CANC = 0.00;
  R->VL_ITEM = 0.00;
  R->VL_DESC = 0.00;
  R->IND_MOV = "";
  R->CST_ICMS = 0;
  R->CFOP = 0;
  R->COD_NAT = "";
  R->VL_BC_ICMS = 0.00;
  R->ALIQ_ICMS = 0.00;
  R->VL_ICMS = 0.00;
  R->VL_BC_ICMS_ST = 0.00;
  R->ALIQ_ST = 0.00;
  R->VL_ICMS_ST = 0.00;
  R->IND_APUR = 0;
  R->CST_IPI = 0;
  R->ENQUAD_IPI = 0;
  R->VL_BC_IPI = 0.00;
  R->ALIQ_IPI = 0.00;
  R->COD_SELO_IPI = "";
  R->QT_SELO_IPI = 0;
  R->CL_ENQ = 0;
  R->VL_UNID = 0.00;
  R->QUANT_PAD = 0.00;
  R->VL_IPI = 0.00;
  R->ENQUAD_PIS = 0;
  R->ENQUAD_COFINS = 0;
  R->COD_CTA = 0;
  R->COD_CLASSIF = 0;
  R->TIPO_RECEITA = 0;
  R->CNPJ = "";
  R->VL_NT = 0.00;
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_63 *R)
{
  R->BC_ST_ORIG_DEST = 0.00;
  R->ICMS_ST_REP = 0.00;
  R->ICMS_ST_COMPL = 0.00;
  R->BC_RET = 0.00;
  R->ICMS_RET = 0.00;
  R->COD_MOD_ULT_E = 0;
  R->NUM_DOC_ULT_E = 0;
  R->SER_ULT_E = "";
  R->DT_ULT_E = 0;
  R->COD_PART_ULT_E = "";
  R->QUANT_ULT_E = 0.00;
  R->VL_UNIT_ULT_E = 0.00;
  R->VL_UNIT_BC_ST = 0.00;
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_65 *R)
{
  R->NUM_TANQUE = "";
  R->QTDE = 0.00;
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_66 *R)
{
  R->LOTE_MED = "";
  R->QTD_ITEM = 0;
  R->DT_FAB = 0;
  R->DT_VAL = 0;
  R->IND_MED = 0;
  R->TP_PROD = 0;
  R->VL_TAB_MAX = 0.00;
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_67 *R)
{
  R->IND_ARM = 0;
  R->NUM_ARM = "";
  R->DESCR_COMPL = "";
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_68 *R)
{
  R->IND_VEIC_OPER = 0;
  R->CNPJ = "";
  R->UF = "";
  R->CHASSI_VEIC = "";
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_75 *R)
{
  R->COD_PROPRIO = "";
  R->COD_ANT_ITEM = "";
  R->NCM = "";
  R->DESCRICAO = "";
  R->DESC_COMPLE = "";
  R->UN_MED_DOC = "";
  R->DESC_UN_DOC = "";
  R->UN_MED_EST = "";
  R->DESC_UN_EST = "";
  R->FAT_CONVERSAO = 0.00;
  R->PROD_SERV = "";
  R->COD_PROD_ANP = "";
  R->COD_BARRAS = "";
  R->TIPO_ITEM = 0;
  R->COD_GENERO_ITEM = 0;
  R->COD_SERVICO = 0;
  R->ALIQ_INT_ICMS = 0.00;
  Limpa(R->R_76);
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_76 *R)
{
  R->DT_INV = 0;
  R->QTD = 0.000;
  R->VL_UNIT = 0.00;
  R->VL_ITEM = 0.00;
  R->IND_PROP = 0;
  R->TXT_COMPL = "";
  R->COD_CTA = "";
  Limpa(R->R_77);
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_77 *R)
{
  R->GRAVAR = false;
  R->NOME = "";
  R->INSCRICAO = "";
  R->TIPO_INSC = 0;
  R->IE = "";
  R->ENDERECO = "";
  R->BAIRRO = "";
  R->CEP = "";
  R->ESTADO = "";
  R->MUNICIPIO = "";
  R->CCD_CONTABIL = 0;
  R->CEI_NIT = "";
  R->IM = "";
  R->TELEFONE = "";
  R->NOME_FANT = "";
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_80 *R)
{
  R->COD_ITEM = "";
  R->DT_FECH = 0;
  R->ESTQ_ABERT = 0.00;
  R->VOL_ENTR = 0.00;
  R->VOL_DISP = 0.00;
  R->VOL_SAIDAS = 0.00;
  R->ESTQ_ESCR = 0.00;
  R->VL_AJ_PERDA = 0.00;
  R->VL_AJ_GANHO = 0.00;
  R->FECH_FISICO = 0.00;
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_81 *R)
{
  R->NUM_TANQUE = 0;
  R->ESTQ_ABERT = 0.00;
  R->VOL_ENTR = 0.00;
  R->VOL_DISP = 0.00;
  R->VOL_SAIDAS = 0.00;
  R->ESTQ_ESCR = 0.00;
  R->VL_AJ_PERDA = 0.00;
  R->VL_AJ_GANHO = 0.00;
  R->FECH_FISICO = 0.00;
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_82 *R)
{
  R->NUM_BICO = 0;
  R->NR_INTERV = "";
  R->MOT_INTERV = "";
  R->NOM_INTERV = "";
  R->CNPJ_INTERV = "";
  R->CPF_INTERV = "";
  R->VAL_FECHA = 0.00;
  R->VAL_ABERT = 0.00;
  R->VOL_AFERI = 0.00;
  R->VOL_VENDAS = 0.00;
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_83 *R)
{
  R->SERIE = "";
  R->FABRICANTE = "";
  R->MODELO = "";
  R->TIPO_MEDICAO = 0;
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_84 *R)
{
  R->NUM_LACRE = "";
  R->DT_APLICACAO = 0;
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Limpa(struct REGISTRO_85 *R)
{
  R->NUM_BICO = 0;
  R->COD_ITEM = "";
  R->NUM_TANQUE = 0;
};

//---------------------------------------------------------------------------
void __fastcall TGrvPH::Novo(eTipo Tipo)
{
  if(Tipo == tp29)
   R_29 = new REGISTRO_29;
  else if(Tipo == tp32)
   R_32 = new REGISTRO_32;
  else if(Tipo == tp33)
   R_33 = new REGISTRO_33;
  else if(Tipo == tp37)
   R_37 = new REGISTRO_37;
  else if(Tipo == tp38)
   R_38 = new REGISTRO_38;
  else if(Tipo == tp41)
   R_41 = new REGISTRO_41;
  else if(Tipo == tp42)
   R_42 = new REGISTRO_42;
  else if(Tipo == tp44)
   R_44 = new REGISTRO_44;
  else if(Tipo == tp46)
   R_46 = new REGISTRO_46;
  else if(Tipo == tp48)
   R_48 = new REGISTRO_48;
  else if(Tipo == tp49)
   R_49 = new REGISTRO_49;
  else if(Tipo == tp50)
   R_50 = new REGISTRO_50;
  else if(Tipo == tp51)
   R_51 = new REGISTRO_51;
  else if(Tipo == tp52)
   R_52 = new REGISTRO_52;
  else if(Tipo == tp53)
   R_53 = new REGISTRO_53;
  else if(Tipo == tp54)
   R_54 = new REGISTRO_54;
  else if(Tipo == tp55)
   R_55 = new REGISTRO_55;
  else if(Tipo == tp58)
   R_58 = new REGISTRO_58;
  else if(Tipo == tp59)
   R_59 = new REGISTRO_59;
  else if(Tipo == tp60)
   R_60 = new REGISTRO_60;
  else if(Tipo == tp61)
   R_61 = new REGISTRO_61;
  else if(Tipo == tp62)
   R_62 = new REGISTRO_62;
  else if(Tipo == tp65)
   R_65 = new REGISTRO_65;
  else if(Tipo == tp66)
   R_66 = new REGISTRO_66;
  else if(Tipo == tp67)
   R_67 = new REGISTRO_67;
  else if(Tipo == tp68)
   R_68 = new REGISTRO_68;
  else if(Tipo == tp75)
   {
    R_75 = new REGISTRO_75;
//   R_75 = new struct REGISTRO_75;
    R_75->R_76 = new REGISTRO_76;
    R_75->R_76->R_77 = new REGISTRO_77;
   }
  else if(Tipo == tp80)
   R_80 = new REGISTRO_80;
  else if(Tipo == tp81)
   R_81 = new REGISTRO_81;
  else if(Tipo == tp82)
   R_82 = new REGISTRO_82;
  else if(Tipo == tp83)
   R_83 = new REGISTRO_83;
  else if(Tipo == tp84)
   R_84 = new REGISTRO_84;
  else if(Tipo == tp85)
   R_85 = new REGISTRO_85;
}

//---------------------------------------------------------------------------